获取的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