我recieving一個SIGABRT錯誤:這是什麼意思? 「'NSUnknownKeyException',原因:...這個類不是密鑰X的編碼兼容密鑰值」?
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key changeToNewView.'
這些都是我的視圖控制器:
import UIKit
class PhotoShareViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var contentTextView: UITextView!
@IBOutlet weak var thatTextField: UITextField!
@IBOutlet weak var thisTextField: UITextField!
var presenter: PhotoShareModuleInterface!
var image: UIImage!
@IBAction func thisUploadPhoto(_ sender: Any) {
if thisTextField.text != "" //&& thatTextField.text != ""{
performSegue(withIdentifier: "segue", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var photoShareLabelViewController = segue.destination as! PhotoShareLabelViewController
photoShareLabelViewController.thisString = thisTextField.text!
// photoShareLabelViewController.thatString = thatTextField.text!
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
imageView.image = image
}
override var prefersStatusBarHidden: Bool {
return true
}
@IBAction func didTapCancel(_ sender: AnyObject) {
presenter.cancel()
presenter.pop()
}
@IBAction func didTapDone(_ sender: AnyObject) {
guard let message = thatTextField.text, !message.isEmpty else {
return
}
guard let messageOne = thisTextField.text, !messageOne.isEmpty else {
return
}
presenter.finish(with: image, content:message)
presenter.dismiss()
}
}
extension PhotoShareViewController: PhotoShareViewInterface {
var controller: UIViewController? {
return self
}
}
PhotoShareLabelViewController:
import UIKit
class PhotoShareLabelViewController: UIViewController {
@IBOutlet weak var thisLabel: UILabel!
@IBOutlet weak var thatLabel: UILabel!
@IBOutlet weak var thisButton: UIButton!
@IBOutlet weak var thatButton: UIButton!
var thisString = String()
// var thatString = String()
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
thisLabel.text = thisString
thisButton.setTitle(thisString, for: UIControlState.normal)
// thatLabel.text = thatString
// thatButton.setTitle(thatString, for: UIControlState.normal)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
我想知道爲什麼會這樣。我在故事板上檢查了所有的IBOutlets和IBActions,他們似乎工作正常。我認爲它出現錯誤的代碼是我的segue。代碼工作正常,直到我試圖在兩個視圖控制器之間傳遞數據。
我做同樣的事情在一個完全空的Xcode項目和傳遞數據的代碼似乎正常工作,但是當我試圖把它放在我的實際工作區好像有問題。
與此錯誤任何幫助將是真棒!
在你的故事板,似乎你的'PhotoShareViewController'有'changeToNewView'連接現在是無效的(不存在了)。 – Larme
您是否嘗試過使用_Find在Project中搜索'changeToNewView' .._(Shift + Cmd + F)?它在故事板內搜索並可能找到被遺忘的連接。 – OOPer
現在我有錯誤{asetValue:forUndefinedKey:]:此類不是關鍵字值,它們對於關鍵字contentTextField而言是符合編碼的。 }但我是一個更多的視圖控制器比原始錯誤 –