5

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?

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Claudio B.
  • 75
  • 4

4 Answers4

1

in .h file add <UIWebViewDelegate>

and in .m:

yourWebview=[[UIWebView alloc]init];
yourWebview.delegate=self;
V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
  • @Thedude:I know that. But he haven't posted any code .So I can only guess the possibilities . And above seems to be best possibility . – V-Xtreme Apr 12 '13 at 11:04
1

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;
}
Prasad G
  • 6,702
  • 7
  • 42
  • 65
1

This problem is usually found on ipad applications .... but you can solve your problem by using [self performselector:afterdelay] , you have to check in selector method whether webview has loaded or not using [m_pWebview loaded]; and according to that perform indicator stopping .... it's not the proper solution but it works .......

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
0

Not an expert on Google API, but as I suspected this might be your reason.

Community
  • 1
  • 1
user523234
  • 14,323
  • 10
  • 62
  • 102