[英]Swift 4 - How to set and show a new root view controller from current view controller
[英]Swift / How to set (and load) a new root view controller
我有一個RootVC。 它是SwipeViewController: UINavigationController
。
在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.