我有一个对象观察者,我只需要检测一件事。一旦我完成它,我想删除它以消除开销。
所以它看起来像这样:
-(void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*) change context:(void*)context{
if ([keyPath isEqual:@"doingSomething"]){
if ([object isDoingSomething] == NO) {
[my_object setDoingSomething: DO_NOTHING_FOREVER];
[my_object removeObserver:self forKeyPath:@"doingSomething"] // <= ERROR eventually
}
}
}
虽然这不起作用,但会抛出如下错误:
NSKVOPendingNotificationRelease “EXC_BAD_ACCESS”
答案 0 :(得分:1)
你不应该在object
上调用删除观察者吗?
[object removeObserver:self forKeyPath:@"doingSomething"];
应该在接收方上调用