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];

posted on 2016-07-21 17:28  纯情的小公鸡  阅读(134)  评论(0编辑  收藏  举报