iPhone : famous crash – “this class is not key value coding-compliant for the key”…
If you came across this error :
*** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myLabel.’
(replace myLabel with any other name you may have used)
In most cases the cause for this error is a renaming of a UI property such asĀ an IBoutlet in Xcode without updating the binding in Interface Builder. When you come across this thing, do the following:
- Look for the controller that holds your property (in the case of the sample above : myLabel)
- Open the controller’s corresponding Nib file in Interface Builder
- Reconnect your UI control (in the case of the sample : a UILabel) to the new property name.
Another sneaky case where this could occur: If you have a Tab Bar Controller, you have to specify the Class of each item on the tab bar. I had created a new view replete with controls and sliders and switches, and had connected them all up properly, and even designated the Class of My new View’s File’s Owner as MyCustomViewController. (name changed to protect the innocent) BUT, I had neglected to also set the Class of the parent Tab Bar Controller item also to MyCustomViewController. Took me a while to figure this one out, because I was focusing on the new view, rather than looking at the parent view with the tab bar.
Dave Richmond
May 19, 2009 at 1:48 am