【发布时间】:2017-01-09 05:33:25
【问题描述】:
我才刚刚开始学习 Swift。
按照教程,AboutViewController 用于设置视图以显示应用程序的信息。
本教程使用 UIWebView 来处理提供内容的 html 文件。但是官方文档建议改用WKWebView。
现在 AboutViewController 的视图由一个背景图像视图和一个关闭视图的按钮组成。
使用 WKWebView 类参考中的 Apple 示例代码
import UIKit
import WebKit
class AboutViewController: UIViewController, WKUIDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if let filePath = Bundle.main.url(forResource: "info", withExtension: "html") {
if let htmlData = try? Data(contentsOf: filePath) {
let baseURL = URL(fileURLWithPath: Bundle.main.bundlePath)
webView.load(htmlData,
mimeType: "text/html",
characterEncodingName: "UTF-8",
baseURL: baseURL)
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func close() {
dismiss(animated: true, completion: nil)
}
}
Xcode 显示以下三个错误
Swift 编译器错误:“AboutViewController”声明中的预期声明
'override' 只能在 didReceiveMemoryWarning() 行上的类成员上指定
只能声明实例方法@IBAction
我还没弄明白为什么。
需要指导,非常感谢!
【问题讨论】: