我通過Xcode的tvOS「選項卡式應用程序」選項創建了一個測試tvOS應用程序。在第一個標籤視圖控制器放置一個UIcollectionView與一些簡單的文本單元格。tvOS:如何處理TabBar和UICollectionView之間的焦點變化並防止崩潰
當應用程序運行時,可以從標籤欄向下移動到UICollectionView,它接受焦點,並且可以在視圖的項目之間移動而不會出現問題。
然而,試圖移動回升到從UICollectionView標籤欄崩潰以下消息的應用程序:
無法投型的值「UITabBarButton」(0x199b92828)到「tabtest.itemCell」( 0x1000153c8)。
我認爲這意味着焦點引擎只是「看到」collectionView,並且我必須添加代碼來處理跳回到UITabBarButton。
我搜索了高和低的信息如何處理焦點變化,並沒有發現任何具體的。作爲iOS/tvOS開發的新手,我可能會錯過某些明顯的東西。
有人可以請解釋如何管理標籤欄和UICollectionView之間的焦點?
這裏是我使用的處理爲重點的UICollectionView代碼:
// For Focus Engine
func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
}
func collectionView(collectionView: UICollectionView, shouldUpdateFocusInContext context: UICollectionViewFocusUpdateContext) -> Bool {
if let cell: UICollectionViewCell = context.nextFocusedView as! itemCell{
_ = self.collectionView.indexPathForCell(cell)
}
return true
}
遲來的感謝賈斯汀。我終於明白代碼是錯誤的,終於弄清楚了。 「如果讓細胞:......」是不必要的,並導致崩潰。 –