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.
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.
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.
}
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.
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.