当在dealloc方法中移除KVO监听时,如何防止崩溃


- (void)dealloc {
    
    @try {
        
        [self.view removeObserver:self forKeyPath:@"frame"];
    }
    @catch(NSException *exception) {
        NSLog(@"--%@", exception);
    }
}

注意:

我并没有在当前类里添加self.view的属性frame的KVO监听,直接移除的,这么写就不会导致崩溃

猜你喜欢

转载自blog.csdn.net/allanGold/article/details/82492914