I have 4 different views (a,b,c,d). User can go from:
a->b,
b->c ,b->d
c->b ,b->d
d-> c, d->b
To load a new vi开发者_开发技巧ew I use navitaion controller push view. My question what is the best solution to handle back button in order to make it always work like this:
d->c
c->b
b->a
regardless of all prior view controller pushes.
In the other words user makes the following sequence of transitions: (ie.a->b->c->b->c->d->c) but when he presses back button I want him to see screen B, not previously pushed D.
I know how to solve it in ugly ways but I expect something more elegant.
UINavigationController supports popping back to a specific view controller through the popToViewController:animated method...
Pops view controllers until the specified view controller is at the top of the navigation stack.
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
Official Apple Docs
I would however recommend rethinking your navigation hierarchy. The Apple Human Interface guidelines recommend following a structured and consistent navigation scheme. Jumping between controllers can be confusing for the user.
精彩评论