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: <NSKeyValueObservationInfo 0x170437f40> (
<NSKeyValueObservance 0x170056770: Observer: 0x14794a520, Key path: resmPercentage, Options: <New: YES, Old: YES, Prior: NO> 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: <NSKeyValueObservationInfo 0x17043ac80> (
<NSKeyValueObserv

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容