1
votes

How to release all viewcontroller inside a UINavigationController ,without releasing UINavigationController object itself.

My case is ,I am having a navigationcontroller with a set of viewcontrollers pushed in it.At certain situation I want set a new viewcontroller as rootViewController for the available navigationcontroller.So I used

"[navigationcontrollerObj initWithRootViewController:viewController]"; method.

It works fine and my new view hierarchy is set properly.But my issue is, previously pushed viewControllers are not been released.

This is how I pushed my viewcontrollers previously

[navigationcontrollerObj pushViewController:viewControllerObj]; viewControllerObj release];

Any help please.....

2
i always release view controller immediately after it is pushed to navigation controllerBryan Chen

2 Answers

3
votes

If what you meant is to pop to the rootviewcontroller, you can try this:

[self.navigationController popToRootViewControllerAnimated:NO];

This will release all the view controllers as well, if you are not retaining it anywhere else. Make sure that you have released all the view controllers after pushing it. Once this is done you can set any view controller as the rootviewcontroller.

1
votes
[self.navigationController popToRootViewControllerAnimated:NO]; will pop all other view controller
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated // use this function to change the root view controller