2014-12-08 79 views
0

我想以視圖控制器的模式呈現視圖控制器,該視圖控制器已嵌入到導航控制器中,然後當用戶按下完成按鈕模式視圖時應該關閉並呈現視圖控制器。關閉模式視圖控制器問題

呈現視圖控制器模態確定,我這樣做,代碼:

@IBAction func openCardPreferences(sender: AnyObject) { 
     let newVC = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("common") as CommonCardParametrsViewController 

     self.presentViewController(newVC, animated: true, completion: { 
     }) 
    } 

但解僱模式視圖控制器支持我到導航的控制器根視圖控制器,而不是「呈現視圖控制器」

@IBAction func applyChanges() { 

     println(self.presentingViewController) 
     // self.delegate?.doneButtonPressed?() 

     self.dismissViewControllerAnimated(true, completion: {}) 
    } 

正如你可能看到我試圖用委託方法解僱控制器,但這不能解決我的問題。

有趣的是,日誌self.presentingViewController返回UINavigation controller實例。

我不明白髮生了什麼事。 我做錯了什麼?

+0

這段代碼應該可以正常工作,對我來說,它總是返回到'呈現視圖控制器',它不是'導航控制器'的'根視圖控制器'。 – gabbler 2014-12-08 09:24:21

回答

0

我移動方法setViewControllersUINavigationController子類從viewWillAppearviewDidLoad這解決了我的問題。