views:

811

answers:

3

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];
+1  A: 

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];
}
jtbandes
Tried it, and it doesnt work. I've even tried reloading data in WillLoad/Didload, and nothin! the label will only update if I go back to the root view controller and then back to the view1 controller. I have no clue why it's not updating!
AWright4911
Verify that viewWillAppear is getting called (it is or something is wrong) AND verify that plistDict has the expected value for the MYOPTION key. These can both be handled by one NSLog that displays the value from the dictionary called from viewWillAppear.
gerry3
I actually had to add viewDidAppear and it worked fine.
AWright4911
A: 

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.

Morion
It's a string. The data is initialized right cause I've used the same method in other places. The problem is the popViewController, Im not sure that it allows the previous VC to update for some reason. In the last 4 lines, Im trying to set the ringtone NSString of CPVC to my new data, it's worked in other areas, just not when view is popped! Is there any other way to get back to the previous controller without "pushViewController"
AWright4911
plistDict is a string????? and you try to find some value for key??? and I cannot imagine when your 4 last lines can work. they are useless. as many peoples below, i offer you to check your plistDict in the viewWillAppear method. it will be caled after your view controller is popped
Morion
A: 

Great thanks, this answer help me a lot!

DImitar