简体   繁体   English

尝试将导航控制器显示为rootViewController时,视图不在View Hierachy中

[英]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.

相关问题 如何在AppDelegate中为导航视图控制器和选项卡控制器设置rootViewController - How to set rootViewController for navigation view controller and tabbar controller in AppDelegate UIPresentationController 呈现导航控制器视图 - UIPresentationController present navigation controller view iOS启动应用程序处于“详细视图”,而不是导航控制器创建的RootVIewController - iOS start app at a “detail view” instead of RootVIewController created by Navigation Controller 从视图控制器呈现导航视图-iOS 7 - Present a navigation view from view controller - IOS 7 使用导航控制器在 Storyboard 中显示视图控制器 - Swift - Present View Controller in Storyboard with a Navigation Controller - Swift 触摸时显示视图控制器 - Present view controller while touching 当自定义viewController作为根视图控制器而不是Navigation Controller作为self.window.rootViewController添加时,视图不会加载 - View is not loaded when custom viewController added as a root view controller instead of Navigation Controller as the self.window.rootViewController 尝试呈现模态视图控制器时的UIViewControllerHierarchyInconsistency - UIViewControllerHierarchyInconsistency when trying to present a modal view controller 当它不是rootviewcontroller且没有导航控制器时,如何从SKScene访问以前的视图控制器? - How can I access the previous view controller from an SKScene, when it's not the rootviewcontroller and there is no navigation controller? 当前视图控制器具有UITabBar但没有UITabBarController时显示当前视图控制器 - Present view controller while current view controller has a UITabBar but no UITabBarController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM