Reputation: 53
How can I detect back in my mapview (master) controller that the detail view controller has been dismissed? I have a mapview with pins and annotations. When the rightCalloutAccessoryView has been tapped on any annotation, a modal detail view controller is called via performSegueWithIdentifier. Incidentally, I don't know if this is correct or not, but the master and detail view controllers are attached by a navigation controller.
My goal is to take conditional action back on the mapview (master view) based on the user action on the detail view controller. Specifically if they have tapped the Remove Pin feature, I want to remove the pin when control returns to the mapview. If they simply tap the Done button, then I want the pin and annotation to remain on the screen.
With my limited knowledge, I'm able to remove the pin with the second line below but the problem is that I can see that the pin and annotation is removed right after the rightCalloutAccessorView icon is tapped and before the detail view is displayed. So what that means is that if the user then taps the Done button on the detail screen, they would then return to the mapview with the pin and annotation removed already. I only want it removed if the user taps the Remove button.
[self performSegueWithIdentifier:@"PinDetail" sender:self];
[self.mapView removeAnnotation:MA];
So my question really are:
Thanks.
Upvotes: 2
Views: 1659
Reputation: 3408
You can use delegate to perform action on mapview based on action in detail view.In performSegueWithIndentifier you can assign your detail view as delegate of mapview and it will perform action for you.
Or you can set target and selector for detail view and when any action happens in detail view you can call that selector whose target is map view, as follows: 1.In performSegue method set target as follows:
[theController setTarget:self andSelector:@selector(performAction)];
where theController is your destination view controller ie detail view controller.
2.In detail view controller .h file
id m_Target;
SEL m_Selector;
In detail view controller.m file:
- (void)setTarget:(id)inTarget andSelector:(SEL)inSelector
{
m_Target = inTarget;
m_Selector = inSelector;
}
3.Before dismissing detail view call
if ([m_Target respondsToSelector:m_Selector]) {
[m_Target performSelector:m_Selector withObject:nil];
}
4.Define performAction in map view controller .m file
Upvotes: 2