Quản lý bộ nhớ là một vấn đề rất quan trọng trong iPhone. Vì vậy, tôi hỏi một câu hỏi rất chung chung. Có hai cách để gọi một viewController của một lớp khác.Làm thế nào để đẩy viewcontroller (view controller)?
Cách 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
Vì vậy, câu hỏi rõ ràng là, đó là cách tốt nhất để gọi viewController của lớp khác? Way1 hoặc Way2?
Đề xuất và nhận xét được mời công khai.
Vui lòng nhận xét và bỏ phiếu.