从Modal View内部推送到iOS NavigationController

时间:2011-11-02 15:20:02

标签: ios uiviewcontroller uinavigationcontroller modal-dialog

我是iOS编程的新手,也是Stack Overflow的新手。我一直试图找到我的问题的答案,但搜索没有产生任何结果。

我正在努力让我的应用程序流下来,但我遇到了问题。我想要发生的是:

初始视图(NavigationController) - >搜索视图(模态) - >在解除视图之前,以编程方式将不同视图从搜索视图推送到初始视图的NavigationController上。

我的理解是,在模态视图中,我应该可以做类似

的事情
[self.parentViewController.nagivationController pushViewController: someView]

但这根本不起作用。在驳回模态视图后,我回到初始视图。

我还尝试将引用传递给初始视图导航控制器,但我似乎无法正常工作。

因此,如果有人知道如何从模态视图中以编程方式将视图推送到导航堆栈,我很乐意学习!我真的开始认为我对模态观点的理解存在根本缺陷。

提前感谢您提供的任何帮助,以及您对完整newb的耐心。

2 个答案:

答案 0 :(得分:1)

Annnnnd,我很蠢。

我有正确的方法,但我花了一天才意识到self.parentViewController返回一个UINavigationController,所以额外的“.navigationController”是完全没必要的。

正确参考:

[self.parentViewController pushViewController: someView]

感谢评论,Rob。

答案 1 :(得分:0)

parentViewController返回nil,但使用presentingViewController有效。 Swift 2.x:

    let vc = storyboard!.instantiateViewControllerWithIdentifier(CustomViewControllerID) as! CustomViewController
    if let navController = presentingViewController as? UINavigationController {
        navController.pushViewController(vc, animated: false)
    }