UIWebView EXC_BAD_ACCESS crash

后端 未结 6 681
无人共我
无人共我 2020-12-13 00:49

I\'m experiencing crashes of an app that uses UIWebView. Usually it\'s when page is not fully loaded and UIWebView is sent stopLoading selector. Or when UIWebView fully load

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 01:21

    You have to stop loading the webView and remove the delegate before leaving the view:

    // ARC (correct solution)
    - (void)dealloc {
        [_webView setDelegate:nil];
        [_webView stopLoading];
    }
    
    // non ARC
    - (void)dealloc {
        [webView setDelegate:nil];
        [webView stopLoading];
        [webView release];
        [super dealloc];
    }
    
    // ARC (older solution)
    - (void)viewWillUnload {
        [webView setDelegate:nil];
        [webView stopLoading];
    }
    

    What Apple documentation is saying: Important Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil. This can be done, for example, in your dealloc method.

提交回复
热议问题