I have an app that switches around to about 10 different view controllers with methods like this:
-(IBAction)pg2button{
pg2 *pg2view = [[pg2 alloc] initWithNibName: nil bundle: nil];
pg2view.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:pg2view animated:YES];
[pg2view release];
}
Where is a good place to release the current view before the next one is presented?
Thanks!
(1) Format your question: add at least 4 spaces before each code line.
(2) Why do you use
initWithNibName:bundle:initializer if you pass nil as NIB name?Just use the regular
init.(3) I see that you already release the view controller.
It will be released one more time (in the background) once you will dismiss it.
(4) If you’ve meant to ask “Where is a good place to dismiss the current view before the next one is presented?” then it depends on your structure.
Usually, the best approach is to add a delegate method in the original view controller, the modal view controller will call that delegate method and the original view controller will dismiss the modal one like this:
[self dismissModalViewControllerAnimated:YES];.EDIT:
Code sample for the delegate:
This is how to implement:
You should add the next code to your modal view controllers:
Don’t forget also to set the delegate property to self (from MainViewController) once you create the modal view controller…