Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios - UIWebView DidFinishLoad not being called

I have a UIWebView that works ok. The delegate is working. When I open a URL, events shouldStartLoadWithRequest and webViewDidFinishLoad are fired.

But when for example I click on a Google search result, only shouldStartLoadWithRequest is fired, and webViewDidFinishLoad is never called.

This is causing problems because if I put a "loading..." indicator on shouldStartLoadWithRequest, in these cases the indicator still remains even after the page is correctly loaded.

Any idea why this is happening?

like image 634
Claudio B. Avatar asked Oct 22 '22 12:10

Claudio B.


2 Answers

in .h file add <UIWebViewDelegate>

and in .m:

yourWebview=[[UIWebView alloc]init];
yourWebview.delegate=self;
like image 160
V-Xtreme Avatar answered Oct 24 '22 01:10

V-Xtreme


When you click on search, the navigationType is UIWebViewNavigationTypeFormSubmitted. So in this case, the return type should be YES. If it is not, webViewDidFinishLoad method is not fired.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"shouldStartLoadWithRequest");

    if ( navigationType == UIWebViewNavigationTypeLinkClicked ){
        NSLog(@"UIWebViewNavigationTypeLinkClicked");

        return YES;
    } 
    if (navigationType ==UIWebViewNavigationTypeFormSubmitted ) {
        NSLog(@"UIWebViewNavigationTypeFormSubmitted");
        return YES;
    }
    if (navigationType ==UIWebViewNavigationTypeBackForward) {
        NSLog(@"UIWebViewNavigationTypeBackForward");
        return YES;
    }
    if (navigationType ==UIWebViewNavigationTypeFormResubmitted) {
        NSLog(@"UIWebViewNavigationTypeFormResubmitted");
        return YES;
    }
    if (navigationType ==UIWebViewNavigationTypeReload) {
        NSLog(@"UIWebViewNavigationTypeReload");
        return YES;
    }



    return YES;
}
like image 26
Prasad G Avatar answered Oct 24 '22 02:10

Prasad G