2
我將在loadView
中創建的所有子視圖設置爲viewDidUnload
中的零。loadView在記憶體警告後無法正確加載我的視圖
我在模擬器中模擬內存警告,並通過viewDidUnload
刪除了我的屏幕外的視圖及其子視圖。但是,當loadView
在看到這些屏幕外視圖後再次被調用時,我的子視圖不會在第二次正確重新創建。例如,我的標籤和表視圖是空的,我在loadView
創建:
CGRect frame = CGRectMake(0, 0, 400, 600);
UIView *theView = [[UIView alloc] initWithFrame:frame];
self.view = theView;
[theView release];
int w = frame.size.width;
int h = frame.size.height;
CGRect tblFrame = CGRectMake(0, h/10, w, h*7/10);
UITableView *tblvw = [[UITableView alloc] initWithFrame:tblFrame style:UITableViewStylePlain];
tblvw.delegate = self;
tblvw.dataSource = self;
self.resourcesTblVw = tblvw;
[tblvw release];
[self.view addSubview:resourcesTblVw];
CGRect lblFrame = CGRectMake(0, 0, w, 36);
UILabel *lbl = [[UILabel alloc] initWithFrame:lblFrame];
lbl.font = [UIFont boldSystemFontOfSize:20];
lbl.backgroundColor = [UIColor colorWithWhite:0.7 alpha:1.0];
lbl.text = name;
self.nameLabel = lbl;
[lbl release];
[self.view addSubview:nameLabel];
想法?