我最近开始学习Swift,需要帮助。该程序之前运行正常,但我不知道我做了什么,现在它不起作用,按钮不出现,它在一个屏幕上崩溃。错误说"由于未捕获的异常终止应用程序' NSUnknownKeyExeption',原因:[setValue:forUndefinedKey:]:此类不是密钥nextButton编码兼容的键值。'我有一个按钮,你点击进入下一个屏幕,但我点击它,它崩溃了。下面是HomeViewController,SecondScreenViewController和ThirdScreenViewController上的代码。
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
class 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个小时的问题。谢谢大家!
答案 0 :(得分:0)
尝试使用Swift 3
public func settingAction(_sender: UIButton) {
let settingStoryboard : UIStoryboard = UIStoryboard(name: "SettingViewController", bundle: nil)
let settingVC = settingStoryboard.instantiateViewController(withIdentifier: "SettingViewController") as! SettingViewController
self.present(settingVC, animated: true, completion: {
})
}