2015-11-17 39 views
0
@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)}) 
} 

我使用賽格瑞連接ViewControllerViewController我有按鈕註銷用戶裏面,它沒有把我所有的方式到rootViewController立即但卡住在「登錄」ViewController然後從底部推動ViewController然後顯示錯誤:警告:嘗試呈現其視圖不在窗口層次結構!查看未查看數字體系呈現導航控制器RootViewController的

+0

你有沒有試過這個問題? http://stackoverflow.com/questions/31876720/presenting-view-controllers-on-detached-view-controllers-is-discouraged-when-pre – OXXY

+0

這沒有奏效,我得到這個錯誤,而不是:警告:嘗試呈現其視圖不在窗口層次結構中! @OXXY – Nathannn

+0

我試過的代碼:'讓MainView:UIViewController = self.presentingViewController! self.dismissViewControllerAnimated(真,完成:{讓故事板:UIStoryboard = UIStoryboard(名稱: 「主」,束:無) 設VC:的UIViewController = storyboard.instantiateViewControllerWithIdentifier( 「視圖控制器」)作爲UIViewController中 讓navigationController = UINavigationController的(rootViewController:vc) MainView.presentViewController(navigationController,animated:true,completion:nil)})'@OXXY – Nathannn

回答

0

從我的理解,你正試圖回到根視圖控制器註銷?

你可以做。 self.navigationController?.popToRootViewControllerAnimated(true)

+0

我已經試過了,查看我編輯的問題 – Nathannn

+0

我想回來的頁面不在同一個頁面作爲視圖控制器與註銷按鈕堆疊。 – Nathannn

+0

好的,但即使在這種情況下,這兩個堆棧也必須在某個地方連接。例如:在堆棧的開始,你有一個導航控制器。你得到的錯誤/警告是你試圖將一個不相關的VC推入堆棧。 想想這樣,導航控制器總是在堆棧的底部。導航控制器推送並彈出其管理的VC。將不相關的VC推入堆棧是不正確的。 如果您想要呈現不在堆棧中的VC,則需要導航回堆棧的根目錄。然後介紹新的VC。 – TheAppMentor

0
let vc: UIViewController = storyboard!.instantiateViewControllerWithIdentifier("ViewController") as UIViewController 

    let navigationController = UINavigationController(rootViewController: vc) 

    self.presentViewController(navigationController, animated: false, completion: nil) 

這不會產生任何錯誤和最近NavigationController連接到ViewController。