我正在使用Swift 3
製作一個簡單的webview
。但運行後只得到空白屏幕。使用Swift在WebView中獲取空白屏幕
它不是打開我在url請求中的鏈接。
import UIKit
class ViewController: UIViewController {
@IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL (string: "http://www.google.net");
let request = URLRequest(url: url!);
webView.loadRequest(request);
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
你從故事板連線WebView? –
是的,我已經做到了。 –
添加一個委託並檢查委託方法: 可選公共func webViewDidFinishLoad(_ webView:UIWebView) 可選公共func webView(_WebView:UIWebView,didFailLoadWithError錯誤:錯誤)。 此外,您還需要在plist中添加應用程序傳輸安全設置。 – rameez