Possible Duplicate:
UINavigationController
I've a stack of UIViewControllers handled by a UINavigationViewController.
Let's say I'm at the UIViewController 7 and I want to come back to the number 2. What's the most convenient way to do it ?
Let's say I dunno what number the destination UINavigationController is, and I want just to come back to "MyCustomViewController" (loaded on the stack). Is there a way to accomplish this ?
My destination UIViewController is not on the stack. So I would like to get rid of the stack, and push it from the rootViewController. I'm currently on the UIViewController number 7. Which code to write exactly ?
thanks
First get the list of view controllers (
[navController viewControllers]
) and get the 2nd view controller ([vcs objectAtIndex:1]
). Then just callpopToViewController:
passing the controller you got before.Get the list of view controller classes (
[[navController viewControllers] valueForKey:@"class"]
) Then check the index of classMyCustomViewController
([vcClasses indexOfObject:[MyCustomViewController class]]
). Get the index of that object, then just pop to that view controller using method described in item (1).Just pop to root view controller and push your wanted view controller afterwards.
精彩评论