WebViewDidFinishLoad not starting when I use goBack

I want to do extra work after loading the webpage, so I am adding code to webViewDidFinished, but it does not seem to work in this situation.

Situation: I visit a webpage with UIWebview and then a link to another, after which I launch

[webview goback]; 

It seems that the page was loaded from the cache, only

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

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

not called.

+4
source share
2 answers

Oddly enough, I suspect this is the right behavior. From an Apple doc:

webViewDidFinishLoad:

Sent after a webview finishes loading a frame.

My bet is that UIWebView caches a certain number of pages, and the goBack and goForward do not guarantee reloading of locations stored in the back-forward list. Nor does webViewDidFinishLoad work.

But even if this might be the right behavior, I would certainly agree that this is a bad API design. There definitely should be a finishLoad -ish method to connect to navigate back / forward / on the page.

0
source

True There is still a way to get information about changing the history stack:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewHistoryDidChange:) name:@"WebHistoryItemChangedNotification" object:nil]; 

Since the UIWebView does not match KVO on canGoBack , this is apparently the only way to enable / disable the potential return button.

+5
source

All Articles