2014-12-08 83 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这解决了我的问题。