KVO崩溃问题 忘记了注销监听
- (void)loadData { [[KINGNetWorkHandler sharedHandler]getEmergencyInfoWithEmId:self.model.emId Block:^(NSDictionary *keyDict, NSError *error) { if (error || [keyDict[@"code"] integerValue]!=0) {return ;} [self.model setValuesForKeysWithDictionary:keyDict]; [[KINGNetWorkHandler sharedHandler] getTaskInfoWithTaskId:self.model.taskId Block:^(NSDictionary *keyDict, NSError *error) { if (error || [keyDict[@"code"] integerValue]!=0) {return ;} self.currentTask = [KINGTaskInfoNetModel mj_objectWithKeyValues:keyDict]; self.currentTask.isFromEmergency = YES; //添加监听当前task的status状态 [self.currentTask addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil]; }]; }];}- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void *)context { if ([object isKindOfClass:[KINGTaskInfoNetModel class]]) { self.model.emStatus = [(KINGTaskInfoNetModel *)object status]; if ([self.model.emStatusString isEqualToString:@"已处理"]) { self.listModel.currentEM = nil; [KINGDataBase saveEmergencyListNetModel:self.listModel]; } }}
- *//问题在这里 忘记了dealloc删除监听-------------------------
- (void)dealloc { [self.currentTask removeObserver:self forKeyPath:@"status" context:nil];//KVO崩溃,添加监听者必须记得取消监听 否则就崩给你看}
*//问题在这里 忘记了dealloc删除监听-------------------------