ios – MKMapView annotationContainer中的连续崩溃:viewForAnnotation

ios – MKMapView annotationContainer中的连续崩溃:viewForAnnotation,第1张

概述我看过其他关于此的报道,似乎都没有适用.我们的应用程序因频繁(但不可靠的可重现性)崩溃而瘫痪,如下所示: Thread 0 name: Dispatch queue: com.apple.main-threadThread 0 Crashed:0 libobjc.A.dylib 0x333a6c98 objc_msgSend + 161 MapKit 我看过其他关于此的报道,似乎都没有适用.我们的应用程序因频繁(但不可靠的可重现性)崩溃而瘫痪,如下所示:

Thread 0 name:  dispatch queue: com.apple.main-threadThread 0 Crashed:0   libobjc.A.dylib                 0x333a6c98 objc_msgSend + 161   MapKit                          0x30be52fc -[MKMapVIEw annotationContainer:vIEwForAnnotation:] + 362   MapKit                          0x30be4f8e -[MKAnnotationContainerVIEw _addVIEwForAnnotation:] + 2703   MapKit                          0x30c0f164 -[MKAnnotationContainerVIEw addVIEwForManagedAnnotation:notifyDelegate:] + 124   MapKit                          0x30c0b874 -[MKMapVIEw(UserpositioningInternal) _runpositioningChange] + 10365   MapKit                          0x30c09a86 -[MKMapVIEw(UserpositioningInternal) _startpositioningChange:] + 226   MapKit                          0x30c0d04a -[MKMapVIEw(UserpositioningInternal) locationManagerUpdatedLocation:] + 5787   CoreFoundation                  0x360bcefc -[NSObject(NSObject) performSelector:withObject:] + 168   CoreFoundation                  0x360fa2f2 -[NSArray makeObjectsPerformSelector:withObject:] + 3949   MapKit                          0x30bfc802 -[MKLocationManager _reportLocationStatus:] + 3410  MapKit                          0x30bfdd6c -[MKLocationManager _reportLocationSuccess] + 3611  MapKit                          0x30bfd9c6 -[MKLocationManager locationManager:dIDUpdatetoLocation:fromLocation:] + 674

关于这一点的报道在网络上发生了很多变化,但许多似乎都没有得到解决.我没有做任何疯狂的事情,只是在地图上显示用户位置和一个标记.我按照我能找到的例子进行了 *** 作,并且我已经查看了goofs的代码,但找不到任何代码.

这是我的MapVIEw委托处理vIEwForAnnotation的方式:

- (MKAnnotationVIEw*)mapVIEw:(MKMapVIEw*)theMapVIEw vIEwForAnnotation:(ID <MKAnnotation>)annotation{    // If it's the user location,just return nil.    if([annotation isKindOfClass:[MKUserLocation class]])    {        return nil;     // Use default system user-location vIEw.    }    else    {        // Try to dequeue an existing pin vIEw first.        MKPinAnnotationVIEw* pinVIEw = (MKPinAnnotationVIEw*)[mapVIEw dequeueReusableAnnotationVIEwWithIDentifIEr:@"stashMarkerID"];        if(!pinVIEw)        {            // If an existing pin vIEw was not available,create one.            pinVIEw = [[[MKPinAnnotationVIEw alloc] initWithAnnotation:annotation                                                       reuseIDentifIEr:@"stashMarkerID"] autorelease];            pinVIEw.pincolor = MKPinAnnotationcolorPurple;            pinVIEw.animatesDrop = YES;            pinVIEw.canShowCallout = NO;        }        else        {            pinVIEw.annotation = annotation;        }        return pinVIEw;    }}

崩溃似乎与用户位置的变化有关,但是一旦添加了用户位置标记,我就不会搞乱它.当我需要刷新另一个地图标记时,我在删除另一个时跳过用户标记:

// Add the marker to the map.// Remove old one(s) first.int i = 0;while(i < [mapVIEw.annotations count]){    if ([[mapVIEw.annotations objectAtIndex:i] isKindOfClass:[StashMarker class]])    {        [mapVIEw removeAnnotation:[mapVIEw.annotations objectAtIndex:i]];    }    else    {        i++;    }}

委托是整个屏幕的控制器,因此它没有被取消分配;屏幕启动时发生崩溃.这不重要,但地图显示如下:

任何猜测或见解将不胜感激!这是在iOS 5.0.1上.

更新:我们发现当没有MKMapVIEw应该存在时,就会发生这种崩溃.包含它的视图早已被d出.我想知道我们是否遇到了这里报道的问题:MKMapView crashes app when view controller popped

更新2:这是另一份基本相同的报告:Why am I crashing after MKMapView is freed if I’m no longer using it?

对于Cocoa来说,这似乎异常混乱,在我们期望释放MapVIEw之后,必须将MKMapVIEw的委托设置为nil.按照这个速度,为什么我们不必对所有接受代表的控制都这样做?

解决方法 好的,这才是真正的答案.它来自Apple文档,但它从MKMapVIEw中丢失了.它仅在其委托协议的文档下找到:

“在发布已设置委托的MKMapVIEw对象之前,请记住将该对象的委托属性设置为nil.您可以在dealloc方法中处理地图视图.”

注意:这也适用于UIWebVIEw.

我在委托的dealloc方法中将MapVIEw的委托指针设置为nil,我们的崩溃似乎已被删除.

总结

以上是内存溢出为你收集整理的ios – MKMapView annotationContainer中的连续崩溃:viewForAnnotation全部内容,希望文章能够帮你解决ios – MKMapView annotationContainer中的连续崩溃:viewForAnnotation所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1007154.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存