Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView shouldStartLoadWithRequest is not called after goBack from cache

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.

like image 812
zeiteisen Avatar asked Oct 04 '22 00:10

zeiteisen


1 Answers

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];
like image 96
user1226119 Avatar answered Oct 07 '22 23:10

user1226119