Moving View Controller to the top of navigation stack iOS

Yahoo

How do I move a VC pushed into navigation stack to be on top?

Suppose I pushed it in this order

Push VC1 
Push VC 2
Push VC 3

So now currently I have VC3 on top. How do I programmatically bring VC2 to front? So that the stack becomes

VC1,VC3,VC2
Alex Kosyakov

As a developer, you have an access to navigation controller stack by manage its viewControllers array:

NSArray *currentStack = self.navigationController.viewControllers

enter image description here

Discussion 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.

Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to false.

It is simple an array, that holds the vcs that are currently in nav's stack and you can manage this array like the others:

NSMutableArray *tempArray = [NSMutableArray arrayWithArray: currentStack];

[tempArray removeObjectAtIndex:1];
[tempArray addObject:secondVC];

self.navigationController.viewControllers = tempArray;

There are a set of available methods that you can play with:

enter image description here

Hope it helps)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

iOS: remove view controller from navigation stack

From Dev

whats the correct way to be back to top view controller in the navigation controller stack?

From Dev

Moving from Navigation controller to parent view controller

From Dev

Skip/Add a View Controller in Navigation Stack

From Dev

Redirect to new view controller in the middle of navigation stack

From Dev

Keep View Controller Out of Navigation Stack

From Dev

Method of UINavigationController to add a view controller to navigation stack?

From Dev

Presenting a view controller modally within a navigation stack

From Dev

How can I manage the potential endless pushing of view controllers onto the navigation controller stack? iOS

From Dev

Moving to another view controller in iOS on Button Click

From Dev

IOS Custom View or Navigation Bar Controller

From Dev

Instantiate view controller from within navigation stack on launch

From Java

How to check if a view controller is presented modally or pushed on a navigation stack?

From Dev

viewDidAppear() called before view controller is pushed onto navigation stack

From Dev

Navigation Controller hides the iAd banner at the top of my view

From Dev

Navigation Controller to View Controller Programmatically Not Working IOS7

From Dev

Ios Swift : Adding or Moving NavigationBar to bottom of the view controller

From Dev

iOS 7 - Add a view to a navigation controller and make it the first view to appear

From Dev

Remove intermediate View Controllers from Navigation Stack - iOS

From Dev

View on top of navigation bar

From Dev

Navigation Bar Navigation Items causing top area of buttons on pushed view controller to not be tappable

From Dev

Auto Layout with navigation bar and view controller (iOS 7)

From Dev

iOS - pop a view controller by panning on the left edge, navigation bar disappears

From Dev

MVYSideMenu using Navigation Controller in all view controllers iOS

From Dev

iOS 10 - View Controller / Navigation Bar Title hidden

From Dev

Show menu controller on top of cell in iOS collection view

From Dev

How to access most top view controller in Xamarin iOS with Mvvmcross?

From Dev

ios navigation Stack Manipulation

From Dev

Navigation controller in modal view

Related Related

  1. 1

    iOS: remove view controller from navigation stack

  2. 2

    whats the correct way to be back to top view controller in the navigation controller stack?

  3. 3

    Moving from Navigation controller to parent view controller

  4. 4

    Skip/Add a View Controller in Navigation Stack

  5. 5

    Redirect to new view controller in the middle of navigation stack

  6. 6

    Keep View Controller Out of Navigation Stack

  7. 7

    Method of UINavigationController to add a view controller to navigation stack?

  8. 8

    Presenting a view controller modally within a navigation stack

  9. 9

    How can I manage the potential endless pushing of view controllers onto the navigation controller stack? iOS

  10. 10

    Moving to another view controller in iOS on Button Click

  11. 11

    IOS Custom View or Navigation Bar Controller

  12. 12

    Instantiate view controller from within navigation stack on launch

  13. 13

    How to check if a view controller is presented modally or pushed on a navigation stack?

  14. 14

    viewDidAppear() called before view controller is pushed onto navigation stack

  15. 15

    Navigation Controller hides the iAd banner at the top of my view

  16. 16

    Navigation Controller to View Controller Programmatically Not Working IOS7

  17. 17

    Ios Swift : Adding or Moving NavigationBar to bottom of the view controller

  18. 18

    iOS 7 - Add a view to a navigation controller and make it the first view to appear

  19. 19

    Remove intermediate View Controllers from Navigation Stack - iOS

  20. 20

    View on top of navigation bar

  21. 21

    Navigation Bar Navigation Items causing top area of buttons on pushed view controller to not be tappable

  22. 22

    Auto Layout with navigation bar and view controller (iOS 7)

  23. 23

    iOS - pop a view controller by panning on the left edge, navigation bar disappears

  24. 24

    MVYSideMenu using Navigation Controller in all view controllers iOS

  25. 25

    iOS 10 - View Controller / Navigation Bar Title hidden

  26. 26

    Show menu controller on top of cell in iOS collection view

  27. 27

    How to access most top view controller in Xamarin iOS with Mvvmcross?

  28. 28

    ios navigation Stack Manipulation

  29. 29

    Navigation controller in modal view

HotTag

Archive