How do you release a view after it's popped?

Discussion in 'iOS Programming' started by mrl72, Jun 23, 2011.

  1. mrl72 macrumors regular

    Joined:
    Apr 20, 2008
    #1
    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.
     
  2. DennisVar macrumors newbie

    Joined:
    Jun 21, 2010
    #2
    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.
     
  3. mrl72 thread starter macrumors regular

    Joined:
    Apr 20, 2008
    #3
    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.
     

Share This Page