I'm very new to iPhone development and Objective-C. Today, I figured out how to open a new ViewController and how to return to the previous one.
Here's how I 开发者_Go百科currently do this:
// In the main view controller I have a method called openSecondView that is defined like this:
- (void) openSecondView:(id)sender {
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:secondView animated:YES];
}
// In the SecondViewController I have a back button that calls a method called closeView that is defined like this:
- (void)closeView:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
My question is, how do you do properly accomplish this?
Should I call [secondView release] after calling presentModalViewController or is this done some what behind the scenes? I ask this because when I was debugging I noticed that presentModalViewController doesn't seem to be a blocking code, the next few lines of code I added seem to execute immediately, without calling dismissModalViewControllerAnimated. Are there any consequences of calling [secondView release] after presentModalViewController?
Any help/advise would be much appreciated.
Just call [secondView release] after calling presentModalViewController. The view controller will be retained until it is dismissed.
精彩评论