From 5aefe4dfd590e1651ba80c5ab391356d3ba01149 Mon Sep 17 00:00:00 2001 From: tentenlee Date: Thu, 13 Sep 2018 16:45:55 +0800 Subject: [PATCH] [Fix] when WebViewController is not called viewDidLoad, then dealloc will crash --- .../AXWebViewController/AXWebViewController.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/AXWebViewController/AXWebViewController/AXWebViewController.m b/AXWebViewController/AXWebViewController/AXWebViewController.m index d56862b..c447f3c 100644 --- a/AXWebViewController/AXWebViewController/AXWebViewController.m +++ b/AXWebViewController/AXWebViewController/AXWebViewController.m @@ -504,10 +504,19 @@ - (void)dealloc { #if AX_WEB_VIEW_CONTROLLER_USING_WEBKIT _webView.UIDelegate = nil; _webView.navigationDelegate = nil; - [_webView removeObserver:self forKeyPath:@"estimatedProgress"]; - [_webView removeObserver:self forKeyPath:@"scrollView.contentOffset"]; - [_webView removeObserver:self forKeyPath:@"title"]; - // [_webView.scrollView removeObserver:self forKeyPath:@"backgroundColor"]; + @try{ + [_webView removeObserver:self forKeyPath:@"estimatedProgress"]; + [_webView removeObserver:self forKeyPath:@"scrollView.contentOffset"]; + [_webView removeObserver:self forKeyPath:@"title"]; + // [_webView.scrollView removeObserver:self forKeyPath:@"backgroundColor"]; + } + @catch (NSException *exception) { + NSLog(@"%@", exception.reason); + } + @finally { + NSLog(@"remove webview Observer fail"); + } + #else _webView.delegate = nil; #endif