[英]UIWebView not loading web page
I've been trying to learn iOS development with Swift but I've been stuck trying to load a simple web page for a week or so. 我一直在尝试使用Swift学习iOS开发,但是我一直试图加载一个简单的网页大约一个星期。 I've looked all around and the following code seems to work for others but when I run the iOS simulator nothing shows up but the background for the UIWebView
. 我到处都是,下面的代码似乎对其他人也有用,但是当我运行iOS模拟器时,除了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.
}
}
You should be using this 你应该用这个
let myURL = NSURL(string: "https://www.google.com")
not fileURLWithPath:
. 不是fileURLWithPath:
The issue is that, by using fileURLWithPath:
, the web view searches the filesystem for a file named "https://www.google.com"
and doesn't find one, as no such file exists. 问题是,通过使用fileURLWithPath:
,Web视图在文件系统中搜索名为"https://www.google.com"
的文件,但找不到该文件,因为不存在这样的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.