KVO: BUG

- (void)viewDidLoad {
    [super viewDidLoad];

 if (self.resumeSourceType == 2){
        [self.myKVO addObserver: self forKeyPath: @"resmPercentage" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context: nil ];
    }

addObserver 与 removeObserver, 一定要 配套使用

- (void)dealloc{
    if (self.resumeSourceType == 2){
        [self.myKVO removeObserver: self forKeyPath: @"resmPercentage" context: nil ];
        
    }

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [self removeObserver: self forKeyPath: @"resmPercentage" context: nil ];
}



搞笑

TheStep[974:194090] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x170013f70 of class ResumeKVOModel was deallocated while key value observers were still registered with it. Current observation info: (
Context: 0x0, Property: 0x170640660>
)'

Œ
差一点

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [self.myKVO removeObserver: self forKeyPath: @"resmPercentage" context: nil ];
}


TheStep[945:188975] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'An instance 0x174014620 of class ResumeKVOModel was deallocated while key value observers were still registered with it.

Current observation info: (

你可能感兴趣的:(KVO: BUG)