How to load URL in UIWebView in Swift?

前端 未结 18 1502
南旧
南旧 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:11

    Try this:

    1. Add UIWebView to View.

    2. Connect UIWebview outlet using assistant editor and name your "webview".

    3. UIWebView Load URL.

      @IBOutlet weak var webView: UIWebView!
      
      override func viewDidLoad() {
         super.viewDidLoad()
          // Your webView code goes here
         let url = URL(string: "https://www.example.com")
         let requestObj = URLRequest(url: url! as URL)
         webView.load(requestObj)
      }
      

    And run the app!!

提交回复
热议问题