Meme Type Error on UiWebView

浪尽此生 提交于 2019-12-11 00:58:24

问题


I have a iOS app which has a uiwebview where it opens a website, but any link clicked in the webview opens up in Safari. In my code bellow, it get a memetype error on the line "webView.load(request)". Can you give me some code so I can fix this? Thanks! (I need to use a UIWebView instead of a WKWebView)

class VideosViewController : UIViewController, UIWebViewDelegate {

@IBOutlet weak var webView : UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    guard let url = URL(string: "http://example.com") else { return }

    let request = URLRequest(url: url)
    webView.load(request)

}

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

    if navigationType == .linkClicked {

        guard let url = request.url else { return true }
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
        return false
    }
    return true
}

}

回答1:


Try to call webView.loadRequest(request). This function has only one URLRequest parameter.



来源:https://stackoverflow.com/questions/40845488/meme-type-error-on-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!