如果我创建一个带有地图视图的ViewController,这是我添加到viewDidLoad的唯一代码:
MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(-90, -180);
[self.mapView addAnnotation:annotation];
[self.mapView removeAnnotation:annotation];
[annotation release];
我收到错误:
An instance 0xa126fa0 of class MKPointAnnotation was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0xa127df0> (
<NSKeyValueObservance 0xa127c90: Observer: 0xa11c530, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0xa127640>
如果我将代码更改为此,那么我不会收到任何错误:
MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(0, 0);
[self.mapView addAnnotation:annotation];
[self.mapView removeAnnotation:annotation];
[annotation release];
唯一的区别是(0,0)在地图中可见,其中,( - 90,-180)不在视野范围内。也就是说,我需要平移地图以将坐标(-90,-180)带入视图。
之前有人遇到此错误,甚至更好地知道如何修复它?
答案 0 :(得分:5)
经过一些测试,我确信它是MKMapView中的一个错误。我只通过添加可见区域中的注释来解决这个问题。更多的工作,但至少它不会崩溃我的应用程序:)