I'm trying to update old carplay to iOS14 support carplay.
Currently, I implemented most UIs.
Simply, my carplay structure looks like this.
| tab1 | *tab2 | tab3 |
---
| fixed item > |
| additional item 1 > |
| additional item 2 > |
| ... |
When user selects tab2, it should shows user's list with few fixed items.
At this point, my question is 'How to update additional items(CPListItem) of tab2'
Because when the carplay app is initialized, the data can not be ready. So at the time I created tab2 template, there is no additinal item.
I thought I can update CPListItem array like
tabbarTemplate.templates.replaceSubrange(tab2-index...tab2-index, with: [newTemplate])
But tabbarTemplate template's templates is immutable (get-only).
now I update tabbarTemplate itself
var mutable = tabbarTemplate.templates // [tab1, tab2, tab3]
mutable.replaceSubrange(....) // change tab2 with new template
tabbarTemplate.updateTemplates(mutable)
It looks weird to me because it updates tabbarTemplate, not tab2.
I wonder if there is better way to update tab2 items.
thanks
Use the CPTabBarTemplateDelegate method to update the contents of the template when it is selected :
func tabBarTemplate(_ tabBarTemplate: CPTabBarTemplate, didSelect selectedTemplate: CPTemplate) {
if let secondTemplate = selectedTemplate as? CPListTemplate {
secondTemplate.updateSections(...)
}
}