IPhone - UIWebView - clicking on the URL before loading the page makes makeFailLoadWithError gives an error

In my iPhone application, I display a webpage in a webview. I applied the delegate method as follows:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error loading the requested URL" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
}

When I open the URL and load half the page, I immediately click on another link on the web page. At the same time, this delegate method is called. How can I prevent the delegation method from being called when the web page is half loaded and the URL link is clicked.

Or some other solution might be to call stopLoading when you click on any URL. How can i do this?

+3
source share
2 answers

How can I prevent a delegate method from being called when the web page is loading halfway and the URL link is clicked.

, error, , .

- stopLoading - URL. ?

webView:shouldStartLoadWithRequest:navigationType:, , - (, , .. navigationType, , ). stopLoading ( webView webView:didFailWithError:, ... . , ).

+2

NSURLErrorCancelled , URLLoadingSystem " ". , , , ... URLLoadingSystem , .

- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
{   
    // If the URLLoadingSystem cancelled the load don't show anything. 
    if ( [error code] == NSURLErrorCancelled ) 
    {
        //...this is called when the load is cancelled...
    }
    else 
    {
        //...handle the error and show the alert ...
    }
}
+4

Source: https://habr.com/ru/post/1785200/


All Articles