Question

i have two viewcontroller. First view controller include a map and annotations, when i touch an annotation my second view come. At second view i touch the delete button. So my first view's content must be refresh before this code : [self.navigationController popViewControllerAnimated:YES]; i need to call viewdidload method or refresh the content of my previous view from second view.

Was it helpful?

Solution

-(void)viewWillAppear:animated

Not sure if its called before [self.navigationController popViewControllerAnimated:YES]; but certainly before you see the view. Make a call to reload your map's annotations in it.

Also make sure to call viewWillAppear super.

If both view are not working form the same data object you'll need a delegate to send the data back.

OTHER TIPS

You can use either delegate pattern ,as Andy said, or NSNotificationCenter . I personally use NSNotificationCenter.

To use notification center you need to add observers to your view controller classes.When you pop your view, you send a notification to center , lets say your notification is update when you notify the center with update , center tells whatever class has update run a method.... it is simple.

[[NSNotificationCenter defaultCenter] postNotificationName:@"update" object:nil];

check this answer for full code: IOS: Move back two views

ViewWillApear or ViewDidApear will be called since there is any object changes in the viewcontroller, but if you want to change your viewcontrollerA from another viewcontrollerB, that require NSNotificationCenter to call the function from viewcontrollerA

you can always use NSNotificationCenter to update your parent viewcontroller

At your parent viewcontroller put this:

//since child view controller calls turnItOff, notification center calls function "turnButtonCountinuesOff"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(turnButtonCountinuesOff) name:@"turnItOff" object:nil];

turnButtonCountinuesOff is your function at parent viewcontroller

At your child viewcontroller put this:

//connect to parent UI view controller calls notification turnItOff.
[[NSNotificationCenter defaultCenter] postNotificationName:@"turnItOff" object:nil];

hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top