NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.’

Okay so here is just another annoying error I faced during development. Here is the error log

NSUnknownKeyException', reason: '[<UILabel 0x17428340> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.'

Reason 1:

Wrong or expired reference of the View(s) to the IBOutlet with the file owner.

In interface builder you linked your IBOutlets from File's Owner when you should link them from parent view

Solution:

I figured out that one of my views are linked to the file owner directly when it has to be linked to some other view (because it’s a subview). I removed the references and added all over again.

Explanation:
Basically I had a view structure like

1) Parent_View
1.1)- Sub_View
1.1.1)= ScrollView1
1.2)- ScrollView2

1.2 contained the Login form where as 1.1.1 has the profile view.

I was trying to switch between these 2 views depending on the user session availability. I accidently attached delegates of the 2 scrollviews with the file owner (which is wrong since I am hiding and un-hiding it from the parent_View). Not only that, I added some UILabels in to one of the scrollViews and gave a reference of the IBOutlets and then changed the names in the .h file (GOD! I know I make silly mistakes all the time).

I removed all the references and removed all the Views I added after last successful build. Then again I added the views with their references one after another.

Reason 2:

In identity Inspector, with in User Defined Runtime Attributes section, make sure you have given  the correct reference to the classes.

This was the main reason why this error arose for me. I immediately corrected the name (it’s case sensitive!) and Viola! and started working as it showed be.

This saved my day (err.. well .. not the whole day, actually it saved an hour before the day ended… 😀 )

Hope this helps you in one way or another. Would love to hear from you guys and how you solved this issue and don’t forget to rate and comment! it’ll be so kind of you if you do.. 🙂

Advertisements

One thought on “NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.’

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s