Contents

CPTabBarTemplate

A container template that displays and manages other templates, presenting them as tabs.

Declaration

@MainActor class CPTabBarTemplate

Overview

CPTabBarTemplate is a container template that displays a collection of other templates, where each template occupies a single tab in the tab bar. At runtime, use maximumTabCount to determine the maximum number of tabs that your tab bar can display.

When creating an instance of CPTabBarTemplate, provide an array of templates for the tab bar to display. CarPlay treats the array’s templates as root templates, each with its own navigation hierarchy. When a tab bar template is the rootTemplate of your app’s interface controller and you use the controller to add and remove templates, CarPlay applies those changes to the selected tab’s navigation hierarchy.

Use a transactional approach when making changes to the tab bar. Retrieve the current set of templates using the templates property. Add, remove, reorder, or make appearance changes to one or more of the array’s templates. For example, use the tabTitle property to update a template’s tab title, or set showsTabBadge to true to add an indicator to a template’s tab. Then call the updateTemplates(_:) method and pass it the updated array. CarPlay commits those changes and updates the tab bar.

When the user selects a tab, the template calls the tabBarTemplate(_:didSelect:) method on its delegate, which is an object you provide that conforms to the CPTabBarTemplateDelegate protocol.

Topics

Creating a Tab Bar Template

Managing Tab Bar Interactions

Managing the Templates

Getting the Selected Template

Instance Methods

See Also

General Purpose Templates