您的位置:首页 > 其它

无敌获取控制器

2016-07-21 17:28 246 查看
swif:

let tabBarController: UITabBarController = UIApplication.sharedApplication().keyWindow?.rootViewController as! UITabBarController

let nav: UINavigationController = tabBarController.selectedViewController as! UINavigationController

接下来就可以push出去

nav.pushViewController(vc, animated: true)

在你箱套太多层view情况下,或者xib情况下无法获取时,就可以使用,万能的

还可以这样子哦,获取你想要的tab

let tabBarController = UIApplication.sharedApplication().keyWindow?.rootViewController

let nav = tabBarController?.childViewControllers

let home:UINavigationController = nav![0] as! UINavigationController

OC:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

UINavigationController * nav = tabBarController.selectedViewController;

UIViewController *viewController = nav.viewControllers[0];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: