この方法で 60 の MKMapViews にオブザーバーを追加しています。
[mapView2.userLocation addObserver:self
forKeyPath:@"location"
options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
context:NULL];
...
-(void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if ([self.mapView isUserLocationVisible]) {
static dispatch_once_t once;
dispatch_once(&once, ^ {
// Code to run once
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.01;
mapRegion.span.longitudeDelta = 0.01;
[mapView setRegion:mapRegion animated: YES];
// and of course you can use here old and new location values
});
for (MKMapView *map in mapViewArray)
{
if ([map isUserLocationVisible]) {
// Code to run once
MKCoordinateRegion mapRegion;
CLLocationCoordinate2D coordinate = [[map.annotations lastObject] coordinate];
mapRegion.center = coordinate;
mapRegion.span.latitudeDelta = 0.01;
mapRegion.span.longitudeDelta = 0.01;
[map setRegion:mapRegion animated: YES];
// and of course you can use here old and new location values
}
}}
}
それ以来、多くのメモリが消費されていることがわかります。これは多くのメモリを消費しますか?viewDidUnload でオブザーバーを削除するにはどうすればよいですか?