Reputation: 7168
I initialize the WebView with this code:
self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
self.webView.delegate =self;
[self.view addSubview:self.webView];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
Afterwards I load a Webpage in the WebView. For example a search for stackoverflow.
Than I hit a button to call goBack
[self.webView goBack];
This delegate method is not called everytime.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
I assume, that the goBack function loads the page from cache because it loads very fast.
Happens on iOS Version 6.1.
Can anyone help me, that the delegate will always be called?
Update: I use shouldStartLoadWithRequest:navigationType: delegate method to get the history back URL.
Upvotes: 5
Views: 3205
Reputation: 324
A better way is to listen the webHistory change notification to detect goBack/goForward actions.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(webViewHistoryDidChange:)
name:@"WebHistoryItemChangedNotification"
object:nil];
Upvotes: 3
Reputation: 4614
Web view goBack delegate methods Loads the previous location in the back-forward list. it directly load the page from cache as you assumed. If you expect web view need to refresh each time while goback you need to customize that function like this. (e.g: Manually call the delegate methods or functionality implement to reload the same page after go back).
- (IBAction)goBackAction:(UIButton *)sender {
[self.webView goBack];
[self webView:self.webView shouldStartLoadWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.stackoverflow.com"]] navigationType:UIWebViewNavigationTypeOther];
}
Upvotes: 1