2015-08-21 68 views
0

我一直在嘗試用Swift學習iOS開發,但我一直試圖加載一個簡單的網頁一個星期左右。我已經看了四周,下面的代碼似乎適用於其他人,但是當我運行iOS模擬器時,什麼也沒有顯示,但是UIWebView的背景。UIWebView不加載網頁

class ViewController: UIViewController { 

    @IBOutlet weak var myWebView: UIWebView! 

    let myURL = NSURL(fileURLWithPath: "https://www.google.com") 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     myWebView.loadRequest(NSURLRequest(URL: myURL!)) 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 
} 

回答

4

您應該使用這個

let myURL = NSURL(string: "https://www.google.com") 

fileURLWithPath:

問題是,通過使用fileURLWithPath:,Web視圖在文件系統中搜索名爲"https://www.google.com"的文件,但沒有找到文件,因爲不存在這樣的文件。