2015-07-10 31 views

回答

0

我沒有很好地陳述我的問題,所以它應得到它的得票率。這花了我很長的時間,但我找到了答案: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 
    } 
} 
相關問題