我最近开始学习Swift,需要帮助。该程序运行良好之前,但我不知道我做了什么,现在它不工作,按钮不会出现,并在一个屏幕上崩溃。一个错误说:“由于未捕获的异常'NSUnknownKeyExeption',原因:[setValue:forUndefinedKey:]终止应用程序:此类不是密钥nextButton编码兼容的关键值。 Ive得到你点击进入到下一个屏幕按钮,但我点击它,它崩溃继承人的代码上HomeViewController,SecondScreenViewController和ThirdScreenViewController在Swift中更改屏幕视图3
HomeViewController
@IBAction func notifiyButtonPressed(_ sender: AnyObject) {
print("Pressed")
self.performSegue(withIdentifier: "ViewSegue", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("View has loaded! ")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
SecondScreenViewController:。
@IBOutlet var textField: UITextField!
@IBAction func nextButtonPressed(_ sender: Any) {
self.performSegue(withIdentifier: "whotoclass", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
self.textField.delegate = self
print("View 2 Loaded")
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//Hide Keyboard when user touches outside keybaord
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
//Presses return key
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return(true)
}
ThirdScreenViewController:
import UIKit
类ThirdScreenViewController:UIViewController的{
@IBOutlet var joshClassButton: UIButton!
@IBAction func joshClassButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
此外,隶属是我Main.storyboard的图像。如果任何人都可以在这里协助,那么这将是一个巨大的帮助,至少在2小时内一直在解决问题。感谢大家!
http://i.imgur.com/QCuJojA.png
你不知何故取消设置类的故事板第二VC的,所以它试图加载普通'UIViewController',这当然没有名为'nextButton'的属性。或者,如果你没有解除课程,那么你必须从第二个VC中删除'nextButton'插座。 – NRitH
您能否包括堆栈跟踪的截图(日志输出在异常之上)? 我的直觉是告诉你摆脱故事板并跑步;这是一个糟糕的工具,长期限制你。如果你开始使用它,请包括堆栈跟踪,我们会看到我们可以做什么。 – Ryan
嘿家伙。非常感谢你的帮助。我自己动手修理。发现我删除了它,但它仍在代码中。再次感谢! –