iOS - navigationController中的奇怪之处

时间:2012-10-17 14:50:48

标签: iphone ios ipad

我创建了一个基于“单一视图应用程序”Xcode模板的应用程序。它有一个导航控制器和一个rootViewController。

当我在rootViewController上时我做了

[self presentModalViewController:nextModalViewController animated:YES];

新的视图控制器是动画的。

我的问题是这个。我按顺序呈现了很多viewControllers,即

A > B > C > D

或换句话说,我使用presentModalViewController从A中呈现B,从B中呈现C等等。是的,我必须使用presentModalViewController,因为我有一个特殊的动画继续在viewControllers之间转换,我不能使用[self.navigationController push ...

我的问题是:当我将presentModalViewController用于导航堆栈时会发生什么?控制器是否被推送到某个堆栈?有没有办法获得在给定时间呈现的所有navigationControllers的引用?这样的导航堆栈?我的意思是,假设我在D上,我想得到D之前所有控制器的列表。

我知道我可以创建属性并传递它。我只是想知道是否已经在iOS上构建了这样的东西。

感谢。

2 个答案:

答案 0 :(得分:1)

在iOS 5及更高版本中,UIViewController具有presentingViewController属性,该属性返回呈现接收器的视图控制器。在iOS 4及更早版本中,使用呈现的视图控制器的parentViewController属性访问其呈现的视图控制器。因此,您可以通过适当地访问这些属性来从D访问C视图控制器。 See the docs for further information.

如果要像链中那样访问所有视图控制器,可以执行以下操作:

UIViewController *node = self;
while (node != nil) {
    // do something with the view controller, then skip to its parent
    node = node.presentingViewController;
    // or node = node.parentViewController; in iOS 4 or older
}

答案 1 :(得分:-1)

我会在每次模态演示后检查UINavigationController中viewControllers属性的大小,并检查它是否增长。

UIViewController *theControllerYouWant = [self.navigationController.viewControllers objectAtIndex:(theIndexOfYourViewController)];