Key Value Observing is the design pattern for this case. This answer works for me.
- (void)viewDidLoad {
[super viewDidLoad];
self.shouldShowInfoView = NO;
[self.mapView addObserver:self
forKeyPath:@"selectedMarker"
options:(NSKeyValueObservingOptionNew |
NSKeyValueObservingOptionOld)
context:NULL];
}
- (void)needToShowInfoView {
self.shouldShowInfoView = YES;
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if ([keyPath isEqual:@"selectedMarker"]) {
if (self.shouldShowInfoView) {
if ([[change objectForKey:NSKeyValueChangeNewKey] isKindOfClass:[NSNull class]]) {
self.mapView.selectedMarker = [change objectForKey:NSKeyValueChangeOldKey];
}
}
}
}