5

I have created a three files SettingsViewController.h, SettingsViewController.m and SettingsViewController.xib.

I am showing the SwttingsViewController.xib on click of a cell in a row. There is a label and slider on xib file. It works fine. But after creating connections using interface builder. i.e drag-drop from redLabel outlet to my Label on xib file i am getting this error and app terminate.

'[<UIViewController 0x3d636d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key redLabel.'

coure2011
  • 40,286
  • 83
  • 216
  • 349

6 Answers6

6

I had a similar issue accept my issue was that interface builder hadn't tidied up an item I'd deleted. So it was left in the source code.

Fixed the issue by going into the xib file. Right click on the file and select "Open As" then "SourceCode. THe errore message I got contained : this class is not key value coding-compliant for the key originalField

my error message as you can see gave me the name of the offending item "originalField" in this case it was a text field i'd removed, but interface builder hadn't cleaned up properly.

I went into the source code and searched for originalField and deleted the reference to it, all fixed.

Harold
  • 121
  • 1
  • 2
  • 7
3

It looks like the File Owner of the SwttingsViewController.xib has the wrong class. Go inside Interface Builder and change the class of the File Owner to be SettingsViewController. See this page for details about File Owner and UIViewController.

Laurent Etiemble
  • 27,111
  • 5
  • 56
  • 81
  • I am pointing to correct file in interface builder. Its giving me same error either my File owner's Type is empty or SettingsViewController. – coure2011 Jun 23 '10 at 09:30
  • Yes you are right, in code i was not initiating the controller correctly. i was doing this (wrong) controller = [[UIViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil]; – coure2011 Jun 23 '10 at 09:39
  • It should be controller = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil]; – coure2011 Jun 23 '10 at 09:40
0

Thanks Harold! Your answer led me to solve mine! I had deleted an NSString variable that the nib hadn't cleared up properly. The quickest way for me was to delete the nib and make another which solved it. Thanks, Gaz.

Gareth Lloyd
  • 1,621
  • 1
  • 10
  • 7
0

The reason this error occurs is usually down to renaming a property or method in source, and not disconnecting the control from the old value and reconnecting the control to the newly named value.

Since we know this error message usually means that you have a control in your xib or storyboard that is connected to a non existent property or action in the source. And remembering each @property creates a setPropertyName setter method and a propertyName getter. You can check each control in the xib in the connections inspector is still connected to a valid IBOutlet or IBAction.

To avoid this issue use the refactor->rename menu option and Xcode will make sure both entries are updated.

maninvan
  • 890
  • 9
  • 10
0

I had the same issue when I made a .xib for an object that subclasses UIView.

The problem was: When creating constraints, there's an "Object" drop down, that contained 2 values: "File's Owner" and my object name: "Popover View".

When selecting "File's Owner", it would fail if I had even a single outlet added. However, when re-adding all outlets with my class name instead: "PopoverView", then it would get created from Nib just fine without the "key value coding-compliant error".

See screenshot. enter image description here

I did double check that my File Owner is set correctly though, by clicking on my top-level view in the Nib: "PopoverView" and selecting the "Custom Class" tab, and making sure it's set to "PopoverView" there. See screenshot: enter image description here

So the only thing that helped me was: making sure my "Popover View" class name is selected Under the "Object" field, when creating the constraint, and NOT File's Owner.

FranticRock
  • 3,233
  • 1
  • 31
  • 56
0

I had this issue but to fix it i had to change my viewcontroller's module field under the class field to none as it was populated with my projects module but that isnt correct.

Fonix
  • 11,447
  • 3
  • 45
  • 74