[英]Swift / How to set (and load) a new root view controller
I have a RootVC. 我有一个RootVC。 It is a
SwipeViewController: UINavigationController
. 它是
SwipeViewController: UINavigationController
。
SwipeViewController SwipeViewController
Within WelcomeNavigationController
, I'm checking a condition. 在
WelcomeNavigationController
,我正在检查条件。 If that condition is true, I want to open the RootVC. 如果该条件成立,我想打开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()
}
}
}
The print statement is executed and some print statements from my RootVC are executed as well. 打印语句将被执行,我的RootVC中的一些打印语句也将被执行。 So in theory the RootVC is loaded.
因此,理论上RootVC已加载。 But it is not visible.
但是它不可见。 How can I make my RootVC visible?
如何使RootVC可见?
Help is very appreciated. 非常感谢您的帮助。
I think you should be add rootVC to current view controller 我认为您应该将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.