我收到了SIGABRT错误:
***由于未捕获的异常终止应用程序' NSUnknownKeyException',原因:' [setValue:forUndefinedKey:]:此类不是键值changeToNewView的键值编码兼容。&# 39;
这些是我的视图控制器:
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项目上做了同样的事情,并且传递数据的代码似乎工作正常,但是当我尝试将它放入我的实际工作空间时似乎有问题。
任何有关此错误的帮助都会很棒!
答案 0 :(得分:1)
您的故事板中有一个视图,连接到控制器中的插座。但你删除了插座。
转到故事板,按住Ctrl键并单击视图,然后单击x。删除连接。