views:

16

answers:

1

Hi,

After adding a view by pushViewController method, there will be a back button in the navigation bar to pop out the view. However, seems that iOS won't distory the view after popping it out. When will it be distory? Can we distory it manually when popping out the view?

thanks.

A: 

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.

Shaggy Frog
thanks Shaggy Frog, but my problem is the view now only release by the system autorelease mechanism, can I release it manually when popping out the view?
Kelvin
First view controllers are what gets popped off the stack, not views. Second, view controllers take care to release their associated view; you shouldn't be worrying about releasing views the way you're describing.
Shaggy Frog