我很迷惑removeFromSuperview的內存管理。子視圖沒有調用dealloc當超級查看(UIViewController)dealloc
這裏是我的代碼:
MySubView *tMySubView = [[MySubView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
tMySubView.center = self.view.center;
tMySubView.tag = 1111;
[self.view addSubview:tMySubView];
[tMySubView release];
「自我」 是的UIViewController。
當「自我」調用dealloc但MySubView沒有調用dealloc。
我知道addSubView retainCount +1。
所以我嘗試添加[tMySubView removeFromSuperview]在 「自我」 的dealloc
而且MySubView的dealloc被稱爲...
我應該添加[子視圖removeFromSuperview]當superView dealloc?
或者superView removeFromSuperview,它會自動調用subView的removeFromSuperview ...?
我找不出來。 :(
謝謝!
MyViewController * tMyViewController = [[[MyViewController alloc] init] autorelease]; \t [tNavigationController pushViewController:tMyViewController animated:YES];我這樣寫。 – wei 2011-03-10 10:43:41
不要混淆viewcontroller和它的視圖。 – Max 2011-03-10 10:49:32
如何創建視圖?在loadView中還是在XIB中? – hennes 2011-03-10 10:53:20