I have a uinavigationcontroller. After logged in i want to remove viewcontrollers like RegisterViewController,LoginViewController etc from UInavigationcontroller stack..
I mean i have to remove a particular view controller from stack ? How its possible. ?
I checked this post
http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller’s-root-view-controller/
So we can take it into an array like
NSArray *allviewcontrollers= [(UINavigationController *)navigationController viewControllers];
But how to do further process.. This question is hunting me for long time..Please answer me ..Thanks in advance
Use this code and enjoy: NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self. navigationController. viewControllers]; // [navigationArray removeAllObjects]; // This is just for remove all view controller from navigation stack.
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: navigationController.viewControllers]; [allViewControllers removeObjectIdenticalTo: removedViewController]; navigationController.viewControllers = allViewControllers;
Here is my solution. You can set the tag or a fixed property to your viewcontrollers, then you could traverse the uinavigationcontroller stack to search the target viewcontroller(vcToRemove) and remove it. This could be safer. The code:
NSInteger tag = vcToRemove.wvTag; NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: vcToRemove.navigationController.viewControllers]; int i = 1; for (i = 1; i <=[allViewControllers count]; i++) { UIViewController *vc = [allViewControllers objectAtIndex:i]; if ([vc isKindOfClass:[MyWebViewController class]]) { if (((MyWebViewController *)vc).wvTag == tag) { [allViewControllers removeObjectAtIndex:i]; break; } } } vcToRemove.navigationController.viewControllers = allViewControllers;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With