我使用下面的代碼添加觀察員:異常的未經處理過的觀察者
[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];
}
}
,但我得到以下錯誤:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: ' ( Context: 0x0, Property: 0x110bf60>): An -observeValueForKeyPath:ofObject:change:context: message was received but not handled. Key path: operations Observed object: {name = 'NSOperationQueue 0x11213c0'} Change:
請告訴我,如果我在觀察者方法中犯了一些錯誤。
感謝,
所有這些代碼粘貼到你這是一個類裏面呢?你在擴展NSObject還是什麼? –
是的..所有這些代碼都在同一個類中,我正在擴展NSObject類。 –