【发布时间】:2014-07-06 01:27:38
【问题描述】:
我正在开始学习这种我非常喜欢的新语言……但它似乎比我预期的要复杂。
我在 youtube (https://www.youtube.com/watch?v=Rva9ylPHi2w) 上举了一个简单的例子,在根 viewController 中构建一个 webView 并加载一个网页。此示例适用于外部网页,但不适用于本地文件。尝试打开本地文件时出现空白屏幕。
以下代码用于 ViewController.swift 文件。
import UIKit
class ViewController: UIViewController {
@IBOutlet var WebView : UIWebView
var URLPath = ""/files/test.html""
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
loadAddressURL()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadAddressURL() {
let requestURL = NSURL (string:URLPath)
let request = NSURLRequest(URL: requestURL)
println("the requestURL is: \(requestURL)")
WebView.loadRequest(request)
}
}
您可以看到我添加了一个 println 来显示正在使用的 URL 请求,并且它向后显示:
使用本地文件,我得到“requestURL 是:/files/test.html”,这是我的示例 html 文件所在的位置。
是我做错了什么还是我应该向 Apple 归档?
【问题讨论】: