开发者

How do I destroy a view that is added by pushViewController?

After adding a开发者_StackOverflow view by pushViewController method, there will be a back button in the navigation bar to pop the view off the stack. However, it seems that iOS won't destroy the view after popping it off the stack so when will it be destroyed? Can we destroy it manually when popping out the view?


Generally the pattern is like this:

- (void)pushSomeViewControllerOnStack
{
    SomeViewController* someViewController = [[SomeViewController alloc] initWithNibName:@"SomeView" bundle:nil];
    [self.navigationController pushViewController:someViewController animated:YES];
    [someViewController release];
}

In other words, the navigation controller will do its own retain of the view controller, which means you also need to release it yourself, since there's an init. The navigation controller will also take care of releasing this controller when appropriate.


You should implement the viewDidUnload and dealloc methods within your UIViewController subclasses.

When a UINavigationController pops a view controller off its stack the code within those methods will be executed.

You should read the View Controller Programming Guide for iOS: Navigation Controllers documentation from Apple's iOS Developer Library as well as the class reference documentation for the UINavigationController and UIViewController classes so that you will better understand the view controller life cycle and what to expect when various application events occur.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜