私はちょうどSwiftを学び始めています。Swift WKWebViewの問題(Appleを使用)サンプルコード
チュートリアルに続いて、AboutViewControllerは、アプリケーションの情報を表示するように設定されたビューです。
チュートリアルでは、UIWebViewを使用してコンテンツを提供するHTMLファイルを処理していました。しかし、公式の文書では、代わりにWKWebViewを使用することをお勧めします。
今、AboutViewControllerのビューは、背景イメージビューとビューを閉じるボタンで構成されています。
WKWebView
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のは以下の3つのエラー
スウィフトコンパイラエラーを示しています。 "AboutViewController" の宣言で予想宣言
- を
'override'は、didReceiveMemoryWarning()の行にあるクラスメンバーに対してのみ指定できます
のみインスタンスメソッドは、私はまだ、なぜ考え出したていない@IBAction
を宣言することができます。
ガイダンスが必要です、よろしくお願い致します。
ありがとうございました! – mediter