-1

Here is the error:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key answerFour.'


Basically I have connected many UITextFields and UISegmentedControls as outlets in my file. It is crashing immediately when the view is opened. I have looked all over the internet for something that would solve my problem but I can't seem to figure it out. Below shows all of the outlets and how they are declared in code.

enter image description here

@IBOutlet var questionType: UISegmentedControl!
@IBOutlet var required: UISegmentedControl!

@IBOutlet var questionTitleInput: UITextField!
@IBOutlet var questionHint: UITextField!


@IBOutlet var questionTitleMulti: UITextField!
@IBOutlet var numAnswers: UISegmentedControl!
@IBOutlet var answerOne: UITextField!
@IBOutlet var answerTwo: UITextField!
@IBOutlet var answerThree: UITextField!
@IBOutlet var answerFour: UITextField!

I could also use some guidance in what information I need to give you to help solve this problem. It really makes no sense to me.

Malexc
  • 82
  • 7
  • Are these all the uses of `answerFour` in your app? Are you certain it is a UITextField, that the class in the nib is the class you copied these outlets from, that this class compiles? – Jonah Jan 13 '16 at 02:09
  • I imagine it is throwing "answerFour" because it is the first one in the list. I imagine all of them will have the same problem. I used the storyboard, so I did the usual ctrl+drag to declare the outlets in my swift file. – Malexc Jan 13 '16 at 02:13
  • No guessing! ;) That's a good hypothesis but I have no way to tell you if it's right. Let's test it. If you remove the `answerFour` binding does it crash on `answerOne`? If so look carefully at which class is reporting this error. It might be that the file's owner for this nib is just a base `UIViewController` and not the more specific subclass you meant to instantiate which has these outlets defined. – Jonah Jan 13 '16 at 02:24
  • This is what I got, [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key answerOne.' I might have changed a few things between these comments. – Malexc Jan 13 '16 at 02:29
  • Well that makes a certain amount of sense: `UIView` does not have an `answerOne` or `answerFour` property for you to set. You probably intended to set these outlets on some other class. Sadly I can't see your nib file from here so I don't know what you connected these outlets to. Take a look at the `Custom Class` section of the `Identity Inspector` for this object in your nib file. – Jonah Jan 13 '16 at 02:43
  • It says UITextField? Did I misunderstand what you just said. – Malexc Jan 13 '16 at 02:55
  • Check the other end of the outlet; it sounds like you are attempting to bind a UITextField to a nonexistent outlet on a UIView – Jonah Jan 13 '16 at 19:11
  • I appreciate your help. I ended up deleting all of the outlets and starting fresh. Works now. – Malexc Jan 14 '16 at 02:10

1 Answers1

0

It is possible that the app is crashing because -

You might have deleted a variable in code that you dragged out of the storyboard as an outlet earlier. Now that variable is gone but the Connections Inspector in Main.storyboard still has reference to that, so during launch when outlets are being set, Main.Storyboard is not able to find the outlet for that Connection in the corresponding view controller class.

Solution - Take a step back, think of the deleted variable and remove its reference from Connections inspector.

Hope that helps.

HsrDev
  • 89
  • 4
  • As you can see in the picture I posted, 1 outlet corresponds to 1 TextField or 1 SegControl. There aren't any extra outlets to be deleted. I'll probably end up deleting everything I created and starting from scratch and see what happens. – Malexc Jan 13 '16 at 02:55