How to load URL in UIWebView in Swift?

前端 未结 18 1470
南旧
南旧 2020-11-29 00:58

I have the following code:

UIWebView.loadRequest(NSURLRequest(URL: NSURL(string: \"google.ca\")))

I am getting the following error:

18条回答
  •  暖寄归人
    2020-11-29 01:21

    In Swift 3 you can do it like this:

    @IBOutlet weak var webview: UIWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Web view load
        let url = URL (string: "http://www.example.com/")
        let request = URLRequest(url: url!)
        webview.loadRequest(request)
    }
    

    Remember to add permission at Info.plist, add the following values:

提交回复
热议问题