popToRootViewControllerAnimated and dealloc all vi

2019-07-16 16:28发布

问题:

I have a UINavigationController that asks for some information and the user navigates until the end, once there, they can Accept or Cancel all the data that has been entered.

It doesn't matter wich option they choose, as they always will go to the first view using

[UINavigationController popToRootViewControllerAnimated:] 

The question is, how I can release/deallocate all the views ?

For example, they start for view 1 and the end is at view 8, once they go directly to the 1 from the 8, how I can release view 2,3,4,5,6,7,8 ?

thanks,

regards,

m.

回答1:

Just allow navigation controller to handle memory for you - it retains controller pushed to its stack and releases them on remove. So if you do not take ownership of your controllers anywhere else they will be deallocated automatically after popped from navigation controller. Basically you should push controllers as follows:

SomeControllerType* controller = [[SomeControllerType alloc] init];
[navigationController pushViewController:controller animated:animated];
[controller release];