Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mrl72

macrumors regular
Original poster
Apr 20, 2008
221
19
May seem like a silly question, but let's say I have a nav controller with a tableview with many rows and each row drills to a detail view containing some labels and images. If I tap row 1 it loads the detail view and its data and updates the objects, then if I pop with the back button and select row 2 when the detail view is shown it shows all the data from the previous record (until it's refreshed). Since I'm pulling data from the web it could be seconds before the labels/images etc. are updated.

Clearly there is a method to release everything on that detail view when I hit back and so to prevent this from happening when I click on the next row. Any ideas?

Thanks.
 
You could, for example, override

Code:
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    // clear out your code
}

In your detail controller and release unneeded data/clear your views.
 
Thank you. What I ended up doing was something like this:

Code:
- (void)viewWillDisappear:(BOOL)animated {
	[self performSelector:@selector(cleanUpView) withObject:nil afterDelay:1.0];
}

-(void)cleanUpView {
	UIView  *view1 = (UIView *)[self.view viewWithTag:99];
	for (UIView *view in view1.subviews) {
		[view removeFromSuperview];
	}
	self.myDict = nil;
	
	[self.myTable reloadData];
}

Having the delay prevents the view from disappearing while the navigation animation is happening.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.