Note that there are some explanatory texts on larger screens.

plurals
  1. POobjective c open links from UIWebView in safari
    text
    copied!<p>I have a UIViewController subclass which includes a UIWebView and implements the UIWebViewDelegate. What i want to do is make links pressed in the UIWebView to open in safari.<br> I've read past questions about this, but still can't make it work. Here is about what i've done: </p> <p>In the <code>- (void)viewDidLoad</code> method of my class i use the following code: </p> <pre><code>[[self articleWebView] setDelegate: self]; [articleWebView loadRequest:requestObj]; </code></pre> <p>I don't want to display the whole html page that is loaded in the articleWebView object, so in the <code>-(void)webViewDidFinishLoad:(UIWebView *)webView</code> method i use this:<br> <code>NSString *content = [articleWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('myDivId')[0].outerHTML;"];</code></p> <p>Then i empty(release) the articleWebView and load the content: </p> <pre><code>[articleWebView release]; articleWebView= [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,380)]; [articleWebView loadHTMLString:content baseURL:[NSURL URLWithString:@"http://www.mysite.gr/"]]; self.view = articleWebView; </code></pre> <p>I tried to use the following, but it's not working </p> <pre><code>-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { NSURL* url = [request URL]; if (UIWebViewNavigationTypeLinkClicked == navigationType) { [[UIApplication sharedApplication] openURL:url]; return NO; } return YES; } </code></pre> <p>Any ideas what i am missing?<br> Thank you in advance.</p> <p>EDIT: As i can see, the shouldStartLoadWithRequest does not get called, so i'm guessing there is something wrong with the delegate of my webView?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload