Недавно я начал изучать Свифт и нуждался в помощи. Раньше программа работала нормально, но я не знаю, что я сделал, и теперь она не работает, кнопки не появляются и сбой на одном экране. Ошибка говорит: "Завершить приложение из-за неотображенного исключения" 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 часа. Спасибо всем!
попробуйте это для 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: {
})
}
UIViewController
, у которого, конечно, нет свойства с именемnextButton
. Или, если вы не сбросили класс, значит, вы удалили выходnextButton
из вашего второгоnextButton
канала.