2016-02-05 90 views
0

我想改变视图控制器后用户登录到我的应用程序从登录故事板到我的主故事板,这项工作成功,但我收到以下警告控制台:从登录故事板移动到主要故事板在斯威夫特没有警告

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)       
}) 

是否有故事板之间移动,以避免此警告消息,更好的办法?

+0

你如何设置你的登录故事板?那也是模式吗? – bolnad

+0

登录页面是loginSystem故事板的初始视图控制器,在此页面上,您可以使用用户名和密码登录。如果信息不正确,则将用户信息与firebase进行核对并提供错误信息,如果信息正确,则将其发送到主菜单 –

回答

0

用户登录后,不再需要登录层次结构。

成功登录后,您需要更改您的mainWindow的根视图控制器,即appDelegate的窗口的rootViewContoller。

同样在用户注销时再次更改窗口的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来推送和弹出其他viewControllers。

+0

谢谢,但我仍然收到同样的错误:2016-02-05 13:30:20.183 Commu [2277:865191]警告:尝试在上呈现,其视图不在窗口层次结构中! –

0

该警告是因为:

self.presentViewController(vc, animated: true, completion: nil)被呈现的viewController为模式图。这应该只用于在短时间内显示屏幕,以便为用户提供一些操作。预期用户将在某一时刻从模态窗口移回。

有一项新功能,称为storyboard reference。这可以让你在故事板之间使用一段时间。

那么你可以使用:

self.performSegueWithIdentifier("segueId", sender: self) 

这是做一个更清洁的方式,并保持故事板里所有的导航控制。

+0

谢谢,我怎么能以编程方式创建segue,因为我仍然想在将用户发送到新的故事板之前进行用户身份验证检查?是他们的解决方案,适用于低于9的ios版本 –