3
votes

When I try to pop a view controller, it doesnt update info for the previous view. Example: I have a cell that displays text in a label in View1. When you click on the cell it goes to View2 (for example) When I choose an option in View2, popViewControllerAnimated is used to go back to View1, however, I want the label to now be updated with the new option in View1.

My dilemma is that when I pop View2, the label in View1 does not update. Any ideas? I've tried adding a [view1 reloadData]; before the view pops, but no luck.

//VIEW1 the cell that displays the label.
    ringLabel = [[UILabel alloc] initWithFrame: CGRectMake(25, 12.7f, 250, 20)];
    ringLabel.adjustsFontSizeToFitWidth = YES;
    ringLabel.textColor = [UIColor blackColor];
    ringLabel.font = [UIFont systemFontOfSize:17.0];
    ringLabel.backgroundColor = [UIColor clearColor];
    ringLabel.textAlignment = UITextAlignmentLeft;
    ringLabel.tag = 0;
    ringLabel.text = [plistDict objectForKey:@"MYOPTION"];
    [ringLabel setEnabled:YES];
    [cell addSubview: ringLabel];
    [ringLabel release];


//VIEW2 when cell clicked 
    CustomProfileViewController *cpvc = [CustomProfileViewController alloc];
    cpvc.ringtone = [ringList objectAtIndex:indexPath.row];
    [cpvc.tblCustomTable reloadData];
    [self.navigationController popViewControllerAnimated:YES];
3

3 Answers

6
votes

You'll want to override -viewWillAppear: on the first view controller and update the label there. (Make sure to also call super).

Example:

- (void)viewWillAppear:(BOOL)animated {
    // This method is called whenever the view is going to appear onscreen.
    // (this includes the first time it appears.)
    ringLabel.text = [plistDict objectForKey:@"MYOPTION"];
    [super viewWillAppear:animated];
}
0
votes

What is your plistDict object? How you initialize it? Are you sure, that it contains right value for your @"MYOPTION" key after the second view hides? As I can see, plistDict is an object inside your first viewController. Also I cannot see any sense in the last 4 lines of your code. They cause not reloading data but memory leak.

0
votes

make sure you aren't losing anything important in your dealloc method. that messed me up for weeks. i was freeing a variable that pointed to the one in my delegate.