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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With