views:

13

answers:

0

I set all the subviews that I created in loadView to nil in viewDidUnload.

I simulate a memory warning in simulator, and my offscreen views and their subviews get removed via viewDidUnload. However, when loadView gets called again as these offscreen views come into view, my subviews don't get recreated properly the second time. For example, my labels and table views are empty, that I created in 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];

Ideas?