开发者

How to properly display a new view and how to go back to the previous view

开发者 https://www.devze.com 2023-02-05 22:41 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消