In building my application which is a tab based application, from the first tab, the user has the option to view their profile information (which is specific to the app). SO have set up UINavigationController with following view controllers:
1 - Edit profile
0 - View profile (also the root view controller for the `UINavigationController`).
The flow I would like to achieve is if a profile has not been set up (i.e. the first time the application is run), I would like to go directly the Edit Profile View, which right now is the default behaviour since that view is at the top of the stack.
The problem I have run into is, if the profile has been set up, how would I go directly to View Profile. I have looked at the documentation for the UINavgationController, and it unclear about popping a view controller off the stack. The method popToViewController:animated return an NSArray of items popped from the stack. Does that mean those view controllers are no longer available, and/or is there a better method to go directly to the view controller that I want?
If you only have two views in the navigation controller, and View is the root view controller, you can make sure that View is the one that is shown by running
popToRootViewControllerAnimated:immediately before or after that tab has been selected on the tab bar controller.If you are in a case where you want Edit to show, run
popToRootViewControllerAnimated:followed bypushViewController:animated:with the Edit view controller.When you want to pop, you can use
popViewControllerAnimated:rather thanpopToViewController:animated. (You only have two view controllers in this nav controller, so ther is only one that will ever be popped.)This seems pretty simple, unless I have misunderstood your question.
The array of view controllers that are returned from the
popToViewController:animatedaren’t needed by most programs. I haven’t really found a need to use this method myself, and, as I said, it doesn’t look like you need it here.