通常,當我使用viewcontroller時,會將當前viewcontroller推開,我使用UINavigationController並push/pop新viewcontrollers並讓它們自己處理所有的dealloc。通過addSubiew添加的子視圖viewcontroller是否需要dealloc?
但是,例如,在這種情況下,我有一個MainViewController,它是應用程序啓動時的默認視圖。我有第二個視圖,稱爲SecondaryViewController,它是主屏幕上的彈出窗口(有點像lightbox)。
下面是代碼來說明:
//From within mainViewController:
secondaryViewController = [SecondaryViewController alloc] initWithNibName:@"SecondaryViewController" bundle:nil];
[self.view addSubview:secondaryViewController.view];
的secondaryViewController界面看起來是這樣的:
//interface
@interface SecondaryViewController : UIViewController
{
IBOutlet UILabel *httpLabel;
IBOutlet UIScrollView *scrollView;
}
@property(retain, nonatomic) IBOutlet UILabel *httpLabel;
@property(retain, nonatomic) IBOutlet UIScrollView *scrollView;
至於實施,我有@synthesize
爲@property
實例變量,但我不做任何手動分配。然而,我沒有把dealloc方法:
- (void)dealloc
{
[httpLabel release];
[scrollView release];
[super dealloc];
}
但我不知道我需要上述。
所以我的問題是以下幾點:
1)我需要在這種情況下,上述dealloc方法?或者更一般地說,子視圖何時需要一個dealloc方法?
2)如果我做或不需要它,取決於我是否通過addSubview或pushViewController添加secondaryViewController?舉例來說,如果我想更換整個mainViewController,與此:
[self.navigationController pushViewController:secondaryViewController animated:NO]
請問secondaryViewController需要一個dealloc方法?
謝謝!
謝謝。然而,我的問題是,我是否需要在secondaryViewController中使用dealloc()方法。 – kurisukun 2012-02-13 01:15:11