从AppDelegate显示两个ViewController
当APP启动时 – 启动SigninView – 它是Okey。 接下来,如果成功 – 我需要showTripController()。 function工作,但没有显示? 什么问题?
func showSigninView() { let controller = self.window?.rootViewController!.storyboard?.instantiateViewControllerWithIdentifier("DRVAuthorizationViewController") self.window?.rootViewController!.presentViewController(controller!, animated: true, completion: nil) } func showTripController() { let cv = self.window?.rootViewController!.storyboard?.instantiateViewControllerWithIdentifier("DRVTripTableViewController") let nc = UINavigationController() self.window?.rootViewController!.presentViewController(nc, animated:true, completion: nil) nc.pushViewController(cv!, animated: true); }
首先你必须在使用窗口之前添加这个:
self.window.makeKeyAndVisible()
另外要记住的是:
有时keyWindow可能已经被nil rootViewController(在iPhone上显示UIAlertViews,UIActionSheets等)的窗口取代,在这种情况下,你应该使用UIView的窗口属性。
所以,而不是使用rootViewController,使用它提出的第一个:
extension UIApplication { class func topViewController(base: UIViewController? = UIApplication.sharedApplication().keyWindow?.rootViewController) -> UIViewController? { if let nav = base as? UINavigationController { return topViewController(base: nav.visibleViewController) } if let tab = base as? UITabBarController { if let selected = tab.selectedViewController { return topViewController(base: selected) } } if let presented = base?.presentedViewController { return topViewController(base: presented) } return base } } if let topController = UIApplication.topViewController() { topController.presentViewController(vc, animated: true, completion: nil) }
replaceshowTripController的最后3行,如下所示:
let nc = UINavigationController(rootViewController: cv)); self.window!.rootViewController = nc
- 在容器视图之间从TextField中委托文本
- 其视图不在窗口层次结构中 – 电子邮件表单
- applicationWillEnterForeground提供一个视图控制器
- Swift:展示主要和替代(login/入职)stream程的最佳方式是什么?
- UIApplicationLaunchOptionsLocalNotificationKey始终为空 – iOS
- 为什么AppDelegate.swift窗口是可选的?
- 在保持TabBar的同时在AppDelagate中打开ViewController
- 如何从AppDelegate中移动这些stream程,并从每个Call中设置个别代理?
- APPDelegate中的openURL转换错误NSString – > String(Swift和iOS8)