在尝试将导航控制器呈现为rootViewController时,不在View Hierachy中查看

时间:2015-11-17 13:39:49

标签: ios swift

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

我使用推送 segue连接ViewController,并在ViewController我有按钮记录用户的内部,它没有把我一直推到rootViewController立即但卡在“登录”ViewController中,然后从底部向上推ViewController,然后显示错误:警告:尝试在其视图中显示不在窗口层次结构中!< /强>

2 个答案:

答案 0 :(得分:0)

根据我的理解,您在注销时尝试返回根视图控制器?

你可以这样做。    self.navigationController?.popToRootViewControllerAnimated(true)

答案 1 :(得分:0)

let vc: UIViewController = storyboard!.instantiateViewControllerWithIdentifier("ViewController") as UIViewController

    let navigationController = UINavigationController(rootViewController: vc)

    self.presentViewController(navigationController, animated: false, completion: nil)

这不会产生任何错误,并将最近的NavigationController连接到ViewController。