繁体   English   中英

MapKit异常:无法删除关键路径“title”的观察者

[英]MapKit exception: Cannot remove an observer for the key path “title”

我遇到了很多这样的崩溃事件。 在我的代码中,我没有在我的MKAnnotation对象上做任何可以解释此异常的KVO。 所以对我来说,它看起来像是一个iOS错误。

有没有其他人遇到类似的崩溃?

*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer  for the key path "title" from  because it is not registered as an observer.'

Thread 0 Crashed:
0   libSystem.B.dylib                   0x000792d4 __kill + 8
1   libSystem.B.dylib                   0x000792bd raise + 17
2   WhereTo                             0x000a430d uncaught_exception_handler (PLCrashReporter.m:137)
3   CoreFoundation                      0x000a0adf __handleUncaughtException + 239
4   libobjc.A.dylib                     0x00006593 _objc_terminate + 103
5   libstdc++.6.dylib                   0x00042df9 __cxxabiv1::__terminate(void (*)()) + 53
6   libstdc++.6.dylib                   0x00042e4d std::terminate() + 17
7   libstdc++.6.dylib                   0x00042f1d __cxa_throw + 85
8   libobjc.A.dylib                     0x000054cb objc_exception_throw + 71
9   CoreFoundation                      0x000a07c9 +[NSException raise:format:arguments:] + 69
10  CoreFoundation                      0x000a0803 +[NSException raise:format:] + 35
11  Foundation                          0x00031b4d -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 545
12  Foundation                          0x000318a1 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 121
13  MapKit                              0x00024e75 -[MKAnnotationContainerView _unregisterObserverForBubbleAnnotation:] + 133
14  MapKit                              0x0001fd29 -[MKAnnotationContainerView setBubbleAnnotationView:] + 73
15  MapKit                              0x0001f4e3 -[MKAnnotationContainerView _showBubbleForAnnotationView:bounce:scrollToFit:userInitiated:avoid:] + 211
16  MapKit                              0x0001f235 -[MKAnnotationContainerView _setSelectedAnnotationView:bounce:pressed:scrollToFit:userInitiated:avoid:] + 357
17  MapKit                              0x0001f0bf -[MKAnnotationContainerView _setSelectedAnnotationView:bounce:pressed:scrollToFit:userInitiated:] + 83
18  MapKit                              0x000248ab -[MKMapView handleTap:] + 195
19  CoreFoundation                      0x0003ebbf -[NSObject(NSObject) performSelector:withObject:] + 23
20  UIKit                               0x0009a3d3 -[UIGestureRecognizer _updateGestureWithEvent:] + 575
21  UIKit                               0x0009a18b -[UIGestureRecognizer _delayedUpdateGesture] + 23
22  UIKit                               0x000017b1 _UIGestureRecognizerUpdateObserver + 437
23  CoreFoundation                      0x00030c59 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 17
24  CoreFoundation                      0x00030acd __CFRunLoopDoObservers + 413
25  CoreFoundation                      0x000280cb __CFRunLoopRun + 855
26  CoreFoundation                      0x00027c87 CFRunLoopRunSpecific + 231
27  CoreFoundation                      0x00027b8f CFRunLoopRunInMode + 59
28  GraphicsServices                    0x000044ab GSEventRunModal + 115
29  GraphicsServices                    0x00004557 GSEventRun + 63
30  UIKit                               0x00037329 -[UIApplication _run] + 413
31  UIKit                               0x00034e93 UIApplicationMain + 671
32  WhereTo                             0x00003475 main (main.m:14)

从OS 4.x开始,我遇到了与MapKit类似的崩溃。 “类似”我的意思是它与KVO和观察者有关,但我不记得细节。

问题是:我有一个类实现MKAnnotation协议。 但在这个类中,我在不使用KVO(直接通过相应的ivar)访问坐标属性:
_coordinate = ....
代替
self.coordinate = ...

似乎Mapkit现在(从OS 4开始)依靠KVO通知来监控注释位置。

事实证明,我从背景线程写入属性是不行的。 如果我确保只从主线程设置它,问题似乎消失了。

备查; 我得到了完全相同的错误,但在我的情况下,它是由于尝试以编程方式选择尚未添加到mapview的注释而引起的。

我有一个类似的问题,但属性getter是一个已定义的函数,但没有setter。 MKAnnotation协议需要一个属性(getter和setter)。

我在两个MKMapView中使用相同的,并在调用removeAnnotations时抛出异常:从第二个映射,这个try-catch修复问题。

@implementation MyAnnotation //<MKAnnotation>
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
{
    @try
    {
        [super removeObserver:observer forKeyPath:keyPath];
    }
    @catch(...)
    {

    }
}
@end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM