嗯,我不确定这是一个真正的问题,但看到错误是不愉快的。出现“thread 1 exc_bad_access(code = exc_i386_gpflt)”错误,模拟器中出现概率约为50%。但实际设备中没有错误。 我尝试使用选项,但没有明显的结果。 我只有WKWebView和一个Button。代码是:
import UIKit
import WebKit
class ViewController: UIViewController {
@IBOutlet weak var WebView: WKWebView!
let all = ["kjhgjhkg","qqqqqqqqq", "wwwwwwwww", "lllllllll", "bbbbbbbb"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
WebView.loadHTMLString("<h1>The first title</h1>", baseURL: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func btnRefresh(_ sender: UIButton) {
let RandomNomber = Int(arc4random_uniform(UInt32(all.count)))
// let myString = all[RandomNomber]
// let myString2 = "<h1>" + myString + "</h1>"
WebView.loadHTMLString("<h1>" + all[RandomNomber] + "</h1>", baseURL: nil)
}
}