开发者

Navigation Controller and Title for the previous screen in Navigation?

So if I am on a screen I can navigate to the next navigation screen using the pushViewController and I simply get to the next screen, with a backButton to the previous screen.

Does the previous screen , (the screen which the back button pushes us to) ... does it have a name ? (Like previousViewController os something like that ) ??

My goal behind this question:

If I have 5 screens (1, 2, 3, 4, 5 respectively)... lets say I navigate from 1 -> 3, and in another case I navigate from 2 -> 3. I want to say that if the "PreviousViewController was 1" then navigate from 3 to 4 (1 -> 3 -> 4), else if the previousViewController was 2, I want to开发者_如何学编程 navigate to 3 to 5 (2 -> 3 -> 5)...

How do I accomplish something like that ?

Thanks !

p.s. I know I could also try something sensible and logical with another approach and just pushViewController accordingly. But if there is a solution for checking the previousViewController, it would make my task easy and would be a great learning experience.


You can actually do that by using the viewControllers property of UINavigationController. This is what Apple says about it:

The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.

Your "previous controller" is what Apple defines "back view controller", corresponding to index n-2:

NSUInteger arraySize = [navController.viewControllers count];
UIViewController* prevController = [navController.viewControllers objectAtIndex:count-2];


Nope, there is no previousViewController. UINavigationController is implemented as a stack so you keep pushing view controllers and those can pop themselves off the stack.

FYI, if you're trying to view all the stack of viewcontrollers then UINavigationController has property called "viewControllers" which is implemented as NSArray.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜