Jacob
Jacob

Reputation: 1896

Deeper understanding of UINavigationController

I'm trying to get a better understanding of creating complex navigations with the UINavigationController. Please, If I'm wrong in any assumption (which is so possible) just let me know.

As far as I see, it seems that UINavigationController is specifically designed to achieve a kind of navigation where pushing a new controller provides a more in-depth detail of data in a "linear" way. You can go further in the navigation by "pushing" or back "popping" the controller.

However, it's usual that the application has in every view a way to go to another view which doesn't have to be the parent and can be in previous levels of the stack (or simply doesn't exists yet). Such applications tend to let the user go anywhere he wants, which seems to conflict with the way UINavigationController works.

It seems obvious to me that if I start to push controllers without control I'll have memory problems.

How can I, for example, go to a view which is two levels down in the stack (for example, what a "Home" button would do)?. Should I save some controllers/views as the initial in a singleton variable for better access and avoid memory problems?

Upvotes: 1

Views: 223

Answers (1)

Anomie
Anomie

Reputation: 94794

You can use popToRootViewControllerAnimated: to get back to the root, or popToViewController:animated: to pop back to an arbitrary previous view controller. You can also use setViewControllers:animated: to directly set the entire stack of view controllers.

Do be careful not to confuse your users, however.

Upvotes: 4

Related Questions