2015-12-24 88 views
6

我想離開初始視圖控制器,並進入空白視圖控制器。這很好,但是這會使空視圖控制器也成爲導航控制器的一部分,這不是我想要的。我想離開視圖控制器。塞格出導航控制器

在視圖控制器我嘗試Segue公司出的,它會彈出它的自我,當我嘗試在視圖中的方法將出現在目標視圖控制器,self.navigationController?.topViewController回報本身,而是self.navigationController?.popViewControllerAnimated(animated)不起作用

enter image description here

回答

4

如果你有navigationController

self.navigationController?.popViewControllerAnimated(false) 

否則做

self.dismissViewControllerAnimated(false, completion: nil) 

更新

轉到您的故事板,選擇要瀏覽並添加一個故事板ID的視圖控制器。確保點擊「使用故事板ID」 enter image description here

轉到類,你想從瀏覽並添加以下代碼

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
// vc is the Storyboard ID that you added 
// as! ... Add your ViewController class name that you want to navigate to 
let controller = storyboard.instantiateViewControllerWithIdentifier("vc") as! ViewController 
self.presentViewController(controller, animated: true, completion: {() -> Void in 
}) 

當你要瀏覽添加該代碼的動作時,使用。

+0

很酷!是在調用segue之前完成的嗎? –

+0

是的,當您想要離開控制器時,請在操作中添加上面的一行。 –

+0

好吧,我做了第一個,但我覺得它是刪除錯誤的視圖控制器,因爲這是行不通的。 –

6

我相信這樣做可以不需要編寫任何代碼。要順着接下去了導航控制器的請按照下列步驟操作:

  1. 建立從具有導航控制器,因爲它的根視圖控制器,你會喜歡去下一個(沒有被裏面的視圖控制器視圖控制器Segue公司導航控制器)
  2. 單擊組合舞蹈新
  3. 打開屬性檢查器
  4. 選擇「類」 - >「現在有模式」
  5. 選擇「存在」 - >「在當代語境中」

enter image description here

+0

這個導航控制器不會被釋放。您仍然可以在模態視圖下看到導航視圖。 –