Kirill Kirill - 1 year ago 163
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() {
webView.delegate = self
webView.loadHTMLString("<a href=\"\">stackoverflow</a>", baseURL: nil)

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

if navigationType == UIWebViewNavigationType.linkClicked {
print ("link clicked")!, options: [:], completionHandler: nil)
return false
if navigationType == UIWebViewNavigationType.other {
print ("other")!, 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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download