zoukankan      html  css  js  c++  java
  • 无敌获取控制器

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

  • 相关阅读:
    第七次上机练习
    第六次作业
    第六次上机练习
    第五次作业
    第五次上机练习
    第四次作业
    第四次上机练习
    第三次上机练习
    第三次作业
    第十一周上机练习
  • 原文地址:https://www.cnblogs.com/YangFuShun/p/5692562.html
Copyright © 2011-2022 走看看