MKPlacemark类的实例0x1d58be70已取消分配

时间:2013-01-30 11:07:16

标签: iphone ios ios6-maps

当我尝试使用此代码使用MKPlacemark在mapview上添加注释时:

for(int i = 0; i < [array count]; i++){
        UsersModel *model = [array objectAtIndex:i];

        CLLocationCoordinate2D newCoordinate;
        newCoordinate.latitude = model.coordinate.latitude;
        newCoordinate.longitude = model.coordinate.longitude;

        NSLog(@"%f",model.coordinate.latitude);
        NSLog(@"%f",model.coordinate.longitude);

        //mPlaceMark = [[MKPlacemark alloc] initWithCoordinate:newCoordinate addressDictionary:nil];

        MKPlacemark *placeMark = [[MKPlacemark alloc] initWithCoordinate:newCoordinate addressDictionary:nil];

        //[self.mapView addAnnotation:mPlaceMark];
        [self.mapView addAnnotation:placeMark];
        //[placeMark retain];
        NSLog(@"%@", self.mPlaceMark);
    }

然后它在我的控制台上出错:

An instance 0x1d58be70 of class MKPlacemark 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 0x1d53de10> (
<NSKeyValueObservance 0x1d58af30: Observer: 0x1d576690, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0x1d58af90>
)

1 个答案:

答案 0 :(得分:0)

貌似,你忘了删除一些abserver。请尝试在您的班级dealloc方法中使用此代码。

 for (id <MKAnnotation> annotation in self.mapView.annotations)
 {
      [[self.mapView viewForAnnotation:annotation] removeObserver:self]; // NOTE: remove ALL observer!
 }

您还应该记得nil您的地图代表:

 self.mapView.delegate = nil;