2017-08-08 100 views
-1

我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項目和傳遞數據的代碼似乎正常工作,但是當我試圖把它放在我的實際工作區好像有問題。

與此錯誤任何幫助將是真棒!

+4

在你的故事板,似乎你的'PhotoShareViewController'有'changeToNewView'連接現在是無效的(不存在了)。 – Larme

+0

您是否嘗試過使用_Find在Project中搜索'changeToNewView' .._(Shift + Cmd + F)?它在故事板內搜索並可能找到被遺忘的連接。 – OOPer

+0

現在我有錯誤{asetValue:forUndefinedKey:]:此類不是關鍵字值,它們對於關鍵字contentTextField而言是符合編碼的。 }但我是一個更多的視圖控制器比原始錯誤 –

回答

1

你在你的故事板連接到您的控制器出口的視圖。但是你刪除了這個插座。

轉到您的故事板,控制+點擊查看和刪除通過點擊X之間的連接。

+0

我控制+點擊我的文檔大綱上的'查看'按鈕的兩個意見,但唯一的事情彈出時,我這樣做是三個選項,沒有他們被填充。當我選擇視圖並轉到連接檢查器時,它看起來不像任何連接。 –

+0

您的故事板中是否仍有名爲'changeToNewView'的視圖?這是你必須按CTRL +點擊並刪除連接的觀點。 –

+0

這就是爲什麼我如此如此困惑,我從來沒有任何視圖叫做'changeToNewView'我有一個名爲segue的標題,我改變了segue的名字,但我仍然得到'changeToNewView'錯誤。您的幫助非常感謝! –

相關問題