显示来自 AppDelegate 的两个 ViewController [英] Show two ViewController from AppDelegate
本文介绍了显示来自 AppDelegate 的两个 ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当 APP 启动时 - 启动 SigninView - 没问题.接下来如果成功 - 我需要 showTripController().功能工作但没有显示?有什么问题?
When APP is Launching - start SigninView - it's Okey. Next if success - I need showTripController(). Function work but nothing show? What's a problem?
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);
}
推荐答案
首先你必须在使用 window 之前添加这个:
First of all you must add this before you use window :
self.window.makeKeyAndVisible()
还有一点要记住:
有时 keyWindow 可能已被 window 替换为 nil rootViewController(在 iPhone 上显示 UIAlertViews、UIActionSheets 等),在这种情况下,您应该使用 UIView 的 window 属性.
因此,不要使用 rootViewController,而是使用它提供的最上面的一个:
So, instead of using rootViewController, use the top one presented by it:
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)
}
这篇关于显示来自 AppDelegate 的两个 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文