2015-08-21 67 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"的文件,但没有找到文件,因为不存在这样的文件。