繁体   English   中英

Swift /如何设置(和加载)新的根视图控制器

[英]Swift / How to set (and load) a new root view controller

我有一个RootVC。 它是SwipeViewController: UINavigationController

SwipeViewController

WelcomeNavigationController ,我正在检查条件。 如果该条件成立,我想打开RootVC。

class WelcomeNavigationController: UINavigationController { 

override func viewWillAppear(animated: Bool) {
        backendless.userService.setStayLoggedIn(true)

    if backendless.userService.currentUser != nil {

        print("currentUser != nil")

        dispatch_async(dispatch_get_main_queue()) {

            let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
            appDelegate.window = UIWindow(frame: UIScreen.mainScreen().bounds)
            let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc : RootVC = storyboard.instantiateViewControllerWithIdentifier("RootVC") as! RootVC
            appDelegate.window?.rootViewController = vc
            appDelegate.window?.makeKeyAndVisible()

        }
    }
}

打印语句将被执行,我的RootVC中的一些打印语句也将被执行。 因此,理论上RootVC已加载。 但是它不可见。 如何使RootVC可见?

非常感谢您的帮助。

我认为您应该将rootVC添加到当前视图控制器

self.addChildViewController(vc)
vc.view.frame = self.view.frame
self.view.addSubview(vc.view)
vc.didMoveToParentViewController(self)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM