【问题标题】:An instance 0x1d58be70 of class MKPlacemark was deallocatedMKPlacemark 类的实例 0x1d58be70 被释放
【发布时间】:2013-01-30 11:07:15
【问题描述】:

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

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>
)

【问题讨论】:

  • 所有纬度都在 -90 到 +90 范围内,所有经度都在 -180 到 +180 范围内吗?增强 NSLogs(例如NSLog(@"latitude = %f",model.coordinate.latitude);),这样您就可以知道数字指的是什么。见stackoverflow.com/questions/5872547/…

标签: iphone ios ios6-maps


【解决方案1】:

看来,你忘了删除一些观察者。尝试在您的课程dealloc 方法中使用此代码。

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

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

 self.mapView.delegate = nil;

【讨论】:

  • 其实我用的是ARC,所以我的代码没有dealloc方法。
  • 在使用 ARC 时,您当然可以定义一个 dealloc 方法。你不能做的是打电话给release。即使使用 ARC,对象也会被释放;只有当dealloc被执行时,不能通过保留/释放来控制...stackoverflow.com/questions/7292119/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-06
  • 2023-03-28
  • 2015-10-07
相关资源
最近更新 更多