[英]Moving from a login Storyboard to the main Storyboard in Swift without Warning
当用户从登录情节提要登录到我的主情节提要后,我试图更改视图控制器,此操作成功完成,但在控制台中收到以下警告:
2016-02-05 01:57:59.553 Commu[4749:160489] Warning: Attempt to present <UITabBarController: 0x7f93285b9d90> on <Commu.LoginViewController: 0x7f9328494e80> whose view is not in the window hierarchy!
我的登录视图控制器中的代码如下:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("MainMenu")
self.presentViewController(vc, animated: true, completion: nil)
})
是否有更好的方式在情节提要之间移动,以避免出现此警告消息?
一旦用户登录,就不再需要登录层次结构。
成功登录后,您需要更改mainWindow的根视图控制器,即appDelegate窗口的rootViewContoller。
同样,当用户注销时,再次更改window的rootViewContoller。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("MainMenu")
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = vc
您还可以在层次结构中包括UINavigationController,以推送和弹出其他viewController。
该警告是因为:
self.presentViewController(vc, animated: true, completion: nil)
将viewController呈现为模式视图。 只能在短时间内显示屏幕,以便为用户提供一些操作。 预期用户将在某个时候从模态窗口移回。
有一个新功能,称为情节提要参考 。 这使您可以在情节提要之间使用序列。
然后,您可以使用:
self.performSegueWithIdentifier("segueId", sender: self)
这是一种更清洁的方法,可将所有导航控件保留在情节提要中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.