Sean Danzeiser
Sean Danzeiser

Reputation: 9243

Showing a UIView subclass - this class is not key value coding-compliant for the key

I am trying to create a custom popup view that can be called from multiple view controllers, but im having some trouble.

I'm able to get it to work fine as long as I write and call a "presentPopup" method from within the viewController itself. Rather then writing an individual method in each VC, i'd much prefer to write a method in a separate class and just pass parameters to personalize it.

Anyway, whenever I try to do so, I keep getting the famous "this class is not key value coding-compliant for the key" error. Just wondering if anyone had any insights as to HOW to make the class key value coding compliant? Or how to go about this in general?? Thanks!!

Upvotes: 3

Views: 2474

Answers (2)

jrturton
jrturton

Reputation: 119292

There is a simple explanation at the end of this answer, but I've seen a few similar questions recently so I thought I'd give a bit of background.

The error should also be telling you which key the class is not key value coding compliant for. The phrasing of your question suggests that you think there is some general bit of code you can add to make a class "key value coding compliant". This isn't the case.

All cocoa / cocoa touch objects are capable of performing key value coding operations. KVC allows you to reach accessor methods by using valueForKey: or setValue:forKey: instead of using the accessor methods directly.

The error you are seeing will be along the lines of:

XXX - this class is not key value coding compliant for key YYY.

XXX is the class in question, YYY is the key. So somewhere, [xxx setValue:something forKey:@"YYY"] is being called.

At this point, you're thinking "but I've never used setValue:forKey in my code!". You may be right. But it is used by the frameworks when you load a xib file - all the outlets are set using key-value coding.

So, you will have an outlet in your xib that is connected to something that has since been removed or renamed in the class it links to. If you're lucky, it will have a little exclamation mark next to it. If you're not, you won't even see it in interface builder and you'll have to edit the xib as source code and remove it from the XML.

Upvotes: 3

graver
graver

Reputation: 15213

You are calling setValue:forKey: method somewhere (probably, on a NSMutableDictionary where you should call setObject:forKey) or something similar...

Upvotes: 0

Related Questions