獲取的UITabBarController我從TabbarController上呈現的ViewController/NavigationController
let planSettingsVC = PlanSettingsViewController.instantiateFromStoryboard()
let planInfoNavCon = UINavigationController(rootViewController: planSettingsVC)
if let myTabBarVC = self.tabBarController as? MyPlanTabBarController {
myTabBarVC.present(planInfoNavCon, animated: true, completion: nil)
}
PlanInfoNavCon
呈現導航控制器被提出,現在我想訪問它呈現的TabBarController。
發現在圖書館:
open var tabBarController: UITabBarController? { get } // If the view controller has a tab bar controller as its ancestor, return it. Returns nil otherwise.
所以,我想對PlanSettingsViewController
print(self.tabBarController)
打印零以下個打印零
print(self.navigationController?.presentingViewController?.tabBarController)
打印零print(self.navigationController.tabBarController)
打印零self.navigationController?.presentingViewController as? MyPlanTabBarController
結果零
我能夠訪問TabBar的ViewController TabBarController self.tabBarController
但
如何訪問TabBarController提出了這個?
P.S.
po self.navigationController
回報<UINavigationController>
和po self.navigationController?.presentingViewController
回報<UIViewController>
我試過這個。 'self.navigationController?.presentingViewController as? MyPlanTabBarController'返回nil – sasquatch
您是否在調試中檢查了值?你確定self.navigationController在那個時候是有效的嗎?如果你*不把它當作? MyPlanTabBarController','self.navigationController?.presentingViewController'的值/類是什麼? – DonMag
是的,我處於調試模式。 'po self.navigationController'返回''和'po self.navigationController?.presentingViewController'返回''。當我嘗試將它轉換爲TabBarController –
sasquatch