Navigation controller and title for previous screen in navigation?

Therefore, if I am on the screen, I can go to the next navigation screen using pushViewController, and I just go to the next screen using the backButton on the previous screen.

Is the previous screen used (the screen on which the back button is pressed) ... does it have a name? (Like the previous control), something like this)

My goal behind this question is:

If I have 5 screens (1, 2, 3, 4, 5 respectively) ... let's say I move from 1 → 3, and in another case I move from 2 → 3. I want to say that if "Previous ViewController was 1 ", then go from 3 to 4 (1 → 3 → 4), otherwise, if the previous ViewController was 2, I want to go to 3 - 5 (2 → 3 → 5) ...

How can I do something like this?

Thank!

ps  I know that I could also try something sensible and logical with a different approach and just pushViewController accordingly. But if there is a solution for checking the previous ViewController, it will facilitate my task and become a great learning experience.

+3
source share
2 answers

You can do this using a property viewControllers UINavigationController. This is what Apple says about it :

The root view controller has index 0 in the array, the rear view controller has index n-2, and the top controller has index n-1, where n is the number of elements in the array.

Your “previous controller” is that Apple defines a “reverse lookup controller” corresponding to index n-2:

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

, . UINavigationController , , .

FYI, view, UINavigationController "viewControllers", NSArray.

0

All Articles