-1
對於前四個選項卡,我使用restoreIdentifier爲每個viewController設置適當的委託。在第5個和第6個標籤的情況下,restoreIdentifier是$ MoreNavigationController $,因爲您不直接跳轉到viewController。在Swift中,如果超過5個選項卡,我如何在tabBarController中通過restoreIdentifier設置委託?
對於前四個選項卡,我使用restoreIdentifier爲每個viewController設置適當的委託。在第5個和第6個標籤的情況下,restoreIdentifier是$ MoreNavigationController $,因爲您不直接跳轉到viewController。在Swift中,如果超過5個選項卡,我如何在tabBarController中通過restoreIdentifier設置委託?
我沒有很好地陳述我的問題,所以它應得到它的得票率。這花了我很長的時間,但我找到了答案:didSelectViewController not getting called when in "More" section。
但由於這是用obj-C編寫的,我以爲我會分享我寫的Swift版本。
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
// If the user hits the "More" tab for the first time, we need to set up tabController as a delegate for More's navigationController
if (viewController == tabBarController.moreNavigationController && tabBarController.moreNavigationController.delegate == nil) {
tabBarController.moreNavigationController.delegate = self
}
setUpDelegates(viewController)
}
// This is called when the user chooses something from the list from 「More」
func navigationController(navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) {
setUpDelegates(viewController)
}
// This manages setting up all view controllers with delegates or whatever when they are selected
func setUpDelegates(viewController: UIViewController) {
if viewController.restorationIdentifier == 「foo」 {
let fooController = viewController as? FooController
fooController?.delegate = dataManager
} else if viewController.restorationIdentifier == 「bar」 {
let barController = viewController as? BarController
barController?.delegate = dataManager
}
}