我正在尝试创建一个具有三个选项卡的应用程序。我已将 ViewController 全部设置好并正常工作,但是当我尝试在除第一个选项卡之外的任何不同选项卡上运行 Web View 时,它会崩溃并显示如下消息:
2016-10-06 23:17:54.565932 Techaway[6827:2354958] Unknown class ThirdViewController in Interface Builder file.
2016-10-06 23:17:59.520639 Techaway[6827:2354958] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Techaway.SecondViewController 0x100f0bc20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Home.'
如果在第一个 ViewController 中它工作得很好,这让我很困惑。
SecondViewController 中的代码示例:
import UIKit
class SecondViewController: UIViewController {
var url = URL(string: "https://example.com/")!
@IBOutlet weak var webView: UIWebView!
@IBAction func home(_ sender: AnyObject) {
webView.loadRequest(URLRequest(url: url))
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
webView.loadRequest(URLRequest(url: url))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我只是不明白为什么它在一个地方有效而在另一个地方不起作用!
最佳答案
您的 xib 中的连接可能较差。因此您需要删除storyboard或xib中未引用的IBOutlet表单UIViewController。
有关此内容的更多信息,请参阅以下链接: What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"
关于ios - 更改选项卡时 Web View 会使选项卡式应用程序崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39906505/