2

How to call a function after UIWebView shouldStartLoadingWithRequest method is finished executing in iOS?

I dont want to use performselector:afterdelay because that may not give accurate result while network is low.

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

3 Answers3

1

use these methods may be it helps you,

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
       return YES;
    }


    - (void)webViewDidFinishLoad:(UIWebView *)webView {
      //this method will call after successful loading
    }


    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
      //this method will call after getting any error while loading the web view.
    }
Balu
  • 8,470
  • 2
  • 24
  • 41
1

Use webViewDidFinishLoad: this method is call after a web view finishes loading.

- (void)webViewDidFinishLoad:(UIWebView *)webView

Parameters

  • webView:
    The web view has finished loading.

  • Availability
    Available in iOS 2.0 and later.

iPatel
  • 46,010
  • 16
  • 115
  • 137
0

The UIWebViewDelegate Protocol provides a few methods which can be used in your situation.

The first method that is called after shouldStartLoadWithRequest is webViewDidStartLoad: which, like its name suggests, is called once the WebView has started loading a frame. From your question, this seems to be the most adequate method.

Other options, which were provided in previous answers, are webViewDidFinishLoad: and webView:didFailLoadWithError: which are respectively called every time the UIWebView finished loading a frame and whenever it fails to load a frame.

Note that this means that all methods described above may get called more than once before the UIWebView has actually finished loading, since they are thrown whenever the UIWebView is about to start, has just started, has finished or has failed loading each frame on a page.

Refer to the UIWebViewDelegate Protocol documentation for more detailed information.

Cezar
  • 55,636
  • 19
  • 86
  • 87