How to cancel UIWebView?

I fashionably present a UIViewController with a UIWebView as my view. How to disable UIWebView when user clicks cancel button on it?

One of my ideas is to link the link to the http: // cancel button and then check

 - (void)webViewDidStartLoad:(UIWebView *)webView 

If webView.request.URL.host isEqualToString:@"cancel" , release the view controller.

Should the host have a dot in it, for example, "cancel.com"?

+7
source share
2 answers

You are on the right track, but you are approaching a little. You do not need or want this to be an HTTP URL. Make your url cancel:

 <a href="cancel:">Thing to click</a> 

Then do webView:shouldStartLoadWithRequest:navigationType: in your business web view. Something like this (untested):

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if ([request.URL.scheme isEqualToString:@"cancel"]) { [self dismissModalViewControllerAnimated:YES]; return NO; } return YES; } 
+8
source

It's not entirely clear if you want to stop loading in the web view or just let go of the modal view controller that contains it.

To stop the download:

 [webView stopLoading]; 

To reject a view controller:

 [self dismissModalViewControllerAnimated:YES]; 

Remember to set the delegate web view to nil before releasing it.

+6
source

All Articles