簡體   English   中英

在沒有警告的情況下從登錄故事板移動到Swift中的主故事板

[英]Moving from a login Storyboard to the main Storyboard in Swift without Warning

當用戶從登錄情節提要登錄到我的主情節提要后,我試圖更改視圖控制器,此操作成功完成,但在控制台中收到以下警告:

2016-02-05 01:57:59.553 Commu[4749:160489] Warning: Attempt to present <UITabBarController: 0x7f93285b9d90> on <Commu.LoginViewController:     0x7f9328494e80> whose view is not in the window hierarchy!

我的登錄視圖控制器中的代碼如下:

dispatch_async(dispatch_get_main_queue(), { () -> Void in
   let storyboard = UIStoryboard(name: "Main", bundle: nil)
   let vc = storyboard.instantiateViewControllerWithIdentifier("MainMenu")
   self.presentViewController(vc, animated: true, completion: nil)                         
})

是否有更好的方式在情節提要之間移動,以避免出現此警告消息?

一旦用戶登錄,就不再需要登錄層次結構。

成功登錄后,您需要更改mainWindow的根視圖控制器,即appDelegate窗口的rootViewContoller。

同樣,當用戶注銷時,再次更改window的rootViewContoller。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("MainMenu")


let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = vc

您還可以在層次結構中包括UINavigationController,以推送和彈出其他viewController。

該警告是因為:

self.presentViewController(vc, animated: true, completion: nil)將viewController呈現為模式視圖。 只能在短時間內顯示屏幕,以便為用戶提供一些操作。 預期用戶將在某個時候從模態窗口移回。

有一個新功能,稱為情節提要參考 這使您可以在情節提要之間使用序列。

然后,您可以使用:

self.performSegueWithIdentifier("segueId", sender: self)

這是一種更清潔的方法,可將所有導航控件保留在情節提要中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM