[英]View not in View Hierachy while trying to present Navigation Controller as rootViewController
@IBAction func logOut(sender: AnyObject) {
PFUser.logOutInBackground()
let MainView: UIViewController = self.presentingViewController!
self.dismissViewControllerAnimated(true, completion: {let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as UIViewController
let navigationController = UINavigationController(rootViewController: vc)
MainView.presentViewController(navigationController, animated: true, completion: nil)})
}
I connect a ViewController
using the Push segue and inside that ViewController
i have button that log the user out, It does not push me all the way to the rootViewController instantly but get stuck in the "login" ViewController
then pushes up the ViewController
from the bottom then showing the error: Warning: Attempt to present on whose view is not in the window hierarchy! 我使用Push命令连接
ViewController
,并在其中的ViewController
有一个将用户注销的按钮,它不会立即将我一直推送到rootViewController,但会卡在“登录” ViewController
然后从底部向上推ViewController
然后显示错误: 警告:尝试显示不在窗口层次结构中的视图!
From what I understand, you are trying to come back to the root view controller on logout? 据我了解,您正在尝试在注销时返回到根视图控制器?
You could just do. 你可以做。
self.navigationController?.popToRootViewControllerAnimated(true)
let vc: UIViewController = storyboard!.instantiateViewControllerWithIdentifier("ViewController") as UIViewController
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: false, completion: nil)
This does not create any error and connects the closest NavigationController to the ViewController. 这不会产生任何错误,并将最近的NavigationController连接到ViewController。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.