Unhandle观察者的例外情况

时间:2013-10-09 13:54:58

标签: ios

我使用以下代码添加观察者:

[self.priorityQueue addObserver:self forKeyPath:@"operations" options:options context:NULL];

并且观察方法定义为:

-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
                     change:(NSDictionary *)change context:(void *)context
{
    if ([object isKindOfClass:[NSOperationQueue class]] && [keyPath isEqualToString:@"operations"]) {
        //calling my method
    }
    else {       
        [super observeValueForKeyPath:keyPath ofObject:object
                      change:change context:context];
    }
}

但我收到以下错误:

  

由于未捕获的异常终止应用' NSInternalInconsistencyException',原因:' (    上下文:0x0,属性:0x110bf60> ):-observeValueForKeyPath:ofObject:change:context:收到消息但未处理。   关键路径:运营   观察对象:{name =' NSOperationQueue 0x11213c0'}   变化:

请告诉我,如果我在观察员方法中犯了一些错误。

谢谢,

1 个答案:

答案 0 :(得分:0)

NSObject没有实现该功能 - 如果您正在扩展NSObject,则永远不会调用super。

来自Apple文档:

 Be sure to call the superclass's implementation *if it implements it*.
 NSObject does not implement the method.

https://developer.apple.com/library/ios/documentation/cocoa/conceptual/KeyValueObserving/Articles/KVOBasics.html

相关问题