Kirill Kirill - 1 month ago 28
iOS Question

Open link in browser on click at UIWebView

I have UIWebView inside UITableViewCell in my nib file:

class MyCell: UITableViewCell, UIWebViewDelegate {

@IBOutlet weak var webView: UIWebView!

override func awakeFromNib() {
super.awakeFromNib()
webView.delegate = self
webView.loadHTMLString("<a href=\"http://stackoverflow.com/\">stackoverflow</a>", baseURL: nil)
}

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {

if navigationType == UIWebViewNavigationType.linkClicked {
print ("link clicked")
UIApplication.shared.open(request.url!, options: [:], completionHandler: nil)
return false
}
if navigationType == UIWebViewNavigationType.other {
print ("other")
UIApplication.shared.open(request.url!, options: [:], completionHandler: nil)
return false
}
return true
}
}


But the method shouldStartLoadWith doesn't call and web site opens inside my small UIWebView.
How can I open link in browser?

Answer

Hii Der i think you should be calling all your methods from tableview controller class and not the tableview cell class try this link i hope it works for you too UITableViewCell With UIWebView Dynamic Height