Hi all,
Below is two sample code of push view controller into a navigation stack. Anyone know which one is a more proper way to push view controller into a navigation controller and why it is. Any comments and suggestions are welcome.
1.) Create a local variable for view controller and release it immediately after push it to navigation controller.
* Should I release firstVC after push it in navigation controller? So far it is work fine for me but from some research I saw some people get their app crash when they release the view controller after push it and fixed if after remove the release message from code block. Am I doing in a right way?
2.) Create an instance variable for a view controller, declare it in header and will be release in dealloc method.
Is it a need to use instance variable? Actually when is a need to use instance variable?
Thanks.
Below is two sample code of push view controller into a navigation stack. Anyone know which one is a more proper way to push view controller into a navigation controller and why it is. Any comments and suggestions are welcome.
1.) Create a local variable for view controller and release it immediately after push it to navigation controller.
Code:
FirstViewController * firstVC = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
[self.navigationController pushViewController:firstVC animated:NO];
[COLOR="Blue"][firstVC release][/COLOR]
* Should I release firstVC after push it in navigation controller? So far it is work fine for me but from some research I saw some people get their app crash when they release the view controller after push it and fixed if after remove the release message from code block. Am I doing in a right way?
2.) Create an instance variable for a view controller, declare it in header and will be release in dealloc method.
Code:
FirstViewController * tempVC = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
self.firstVC = tempVC;
[tempVC release];
[self.navigationController pushViewController:firstVC animated:NO];
-(void)dealloc
{
[super dealloc];
[self.firstVC release];
}
Is it a need to use instance variable? Actually when is a need to use instance variable?
Thanks.