Monitoring the MKMapView Region through KVO?

I have an object that interests me when the MKMapView scope changes. However, this object is not a delegate of the map view. I am trying to do the following where map is MKMapView:

 [map addObserver:self forKeyPath:@"region" options:0 context:nil]; 

However, observeValueForKeyPath:ofObject:change:context: not returned.

As an interim solution, I have a map delegate letting this other object know when the map area has changed, but I would like to parse the two objects, since they are really not connected.

+4
ios mkmapview key-value-observing
source share
1 answer

In Cocoa (Touch), the properties of infrastructure objects are guaranteed only in compliance with KVO , if specified in the documentation . Documents for -[MKMapView region] do not require this requirement, so you should not try to use KVO. Even if it worked, you won’t be guaranteed full compliance or continued success.

Instead, you will need to use the delegate method and other messages from it. Perhaps your delegate could broadcast NSNotification to achieve a similar effect for KVO.

+9
source share

All Articles