美文网首页
KVO: BUG

KVO: BUG

作者: plantAtree_dAp | 来源:发表于2017-02-20 12:00 被阅读40次
    - (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

    相关文章

      网友评论

          本文标题:KVO: BUG

          本文链接:https://www.haomeiwen.com/subject/rqgswttx.html