Memory management is a very important issue in iPhone. So I am asking a very general question.
There are two ways to call a the viewController of another class.
Way 1:
AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
Way 2:
#import "AnotherClassViewController.h"
@interface ThisClassViewController : UIViewController{
AnotherClassViewController *myViewController;
}
@property (nonatomic, retain) AnotherClassViewController *myViewController;
@end
@implementation ThisClassViewController
@synthesize myViewController;
- (void) pushAnotherViewController{
if(self.myViewController == nil){
AnotherClassViewController *tempViewController = [[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil];
self.myViewController = tempViewController;
[tempViewController release];
}
[self.navigationController pushViewController:myViewController animated:YES];
}
- (void)dealloc{
self.myViewController = nil;
}
@end
So the obvious question is, which is the best way to call the viewController of other class ?
Way1 or Way2?
Suggestions and comments are openly invited.
Please comment and vote.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…