wk下addObserver后未释放导致的闪退

2019-03-19  本文已影响0人  zttjhm

bug描述:

An instance 0x10e2a8c00 of class WKWebView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x17443b3c0> ( <NSKeyValueObservance 0x174654ca0: Observer: 0x10deef750, Key path: title, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x174654cd0> )

原因:

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    [self.mWebView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];

}

解决方案:

在dealloc中添加释放代码

-(void)dealloc{

    [self.mWebView removeObserver:self forKeyPath:@"title"];

    [[NSNotificationCenter defaultCenter] removeObserver:self];

}

上一篇 下一篇

猜你喜欢

热点阅读