Search code examples
iosuiwebviewuiwebviewdelegate

webViewDidFinishLoad is not fired when I use goBack


I want to do some extra work after the webpage is loaded, so I add some code in webViewDidFinished, but it seems in this situation it's not working.

Situation:I visit a web page with UIWebview then click a link to another, after that, I run

[webview goback];

It seems the page was loaded from cache, only

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

is called,

- (void)webViewDidFinishLoad:(UIWebView *)webView;

is not called.


Solution

  • However quirky, I suspect that this is correct behaviour. From the Apple doc:

    webViewDidFinishLoad:

    Sent after a web view finishes loading a frame.

    My bet is that the UIWebView caches a certain number of pages, and the goBack and goForward methods do not guarantee that locations stored in the back-forward list are reloaded. And thus does not fire webViewDidFinishLoad.

    But even though this is might be correct behaviour, I would certainly agree that this is bad API design. There should definitely be a finishLoad-ish method to hook into for back/forward/in-page navigation.