How to put a view from any point in the navigation stack into an arbitrary controller

I am working on a navigation application and I have selected it so that I can push and configure controllers on the stack and beyond. It is simple enough to move forward - just press the new controller. And moving back is easy as long as you go to the root view controller. There is a method called popToViewController:animated, but I did not create the controller I want to appear with from my current view controller, so the compiler complains that I did not declare it. I know this is the second controller on the stack (one above the root). Can I use this to get there?

+4
source share
2 answers

The viewControllers property for the UINavigationController has viewControllers to be clicked on, so you can use this and your knowledge of which view controller it should pop onto this view controller. There is a link here UINavigationController ref

+4
source

Usually I create a NavigationController object that has information about my UINavigationController and my view controllers. If you give each of your VC a link to such an object, or make it single, then it will be able to handle things like this for you.

There is nothing wrong with embedding navigation logic in controllers, but this can complicate their work when they know about all the other controllers. The encapsulating navigation logic in the shared object simplifies the understanding and support of your application.

Ymmv

+1
source

All Articles