UIWebView & NavigationController crashes while loa

2019-09-13 08:49发布

问题:

I have very weird problem

I build a simple app with UIWebView and NavigationController but the problem is when the seconds page is loading and I go back to the first page and visited a link the APP crashes and the console says nothing

Here is my code on finish loading

-(void)webViewDidFinishLoad:(UIWebView *)aWebView {
    NSString *str = [aWebView stringByEvaluatingJavaScriptFromString:@"document.title"];
    self.navigationItem.title = str; 
     [navigationActivity stopAnimating];
}

and this for the web view should start loading

if(navigationType == UIWebViewNavigationTypeOther)
    {
        NSURL *url2 = [request URL];
        NSString *URLStr = [url2 absoluteString];

        RootViewController* viewController = [[RootViewController alloc] init];
        NSString *holder = [self getQueryStringInner:URLStr];
        [self getQueryString:URLStr];
        if([holder length] != 0 && [flag length] != 0 && !facebook )
        {

            appDelegate.title =@"Title"; 
            appDelegate.query = queryString;
            appDelegate.url = holder; 

            [self.navigationController pushViewController:viewController animated:YES];
            [viewController release];
            return NO;
        }
}

I am really new to Objective-c and iOS development so any help will be appreciated

Any Help

回答1:

Seems that the necessary step is to call [webView stopLoading] in your viewWillDisappear. Apparently the web view delegate was sending the webViewDidFinishLoading method message to a deallocated instance. Glad you got it worked out.