PDA

View Full Version : RootViewController is not key value coding-compliant




danielpunt
Sep 4, 2008, 08:11 AM
I have a RootViewController which loads another view called MainViewController like this:

MainViewController *viewController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
self.mainViewController = viewController;


And in the MainViewController I have an IBOutlet to an ActivityIndicatorView that I have connected in my MainView.xib

I can build my app without a warning, but when I run the app it causes this exception :
'NSUnknownKeyException', reason: '[<RootViewController 0x44e660> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loadIndicator.'

I'm not shure if it has anything to do with this error, but I have declared a @property and @synthesize for loadIndicator in the MainViewController.

Can somebody please direct me to the right direction? Thanks. :)



MontyClift
Sep 4, 2008, 10:34 AM
Have you properly linked the view controller code file up to the xib in interface builder? I came across this error a couple of times when I hadnt done that

sabernar
Nov 2, 2008, 10:21 AM
Did you figure this out? I'm having the same problem. I have a tabbarcontroller that I'm loading a xib into each tab. If I remove the xib from the tabbarcontroller (in Interface Builder), then the app opens successfully (but without the correct view in the tab). If I add the xib into the tabbarcontroller, it crashes with:

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

sabernar
Nov 2, 2008, 11:10 AM
Problem solved. I had to set the Class Identity to the name of the class that is loaded in. I thought that specifying the nib file was enough, but it looks like you need to also set the class for the tab view.

xilus
Mar 6, 2009, 12:50 AM
Thank you, This thread solved my problem.
In return I am posting images for any others that find this thread on google.
(I am sure there will be quite a few)
You must enter the class name here
http://web.me.com/dmwilliams/images/code01.png
AND ALSO.. the nib name here
http://web.me.com/dmwilliams/images/code02.png

jagatnibas
Mar 10, 2009, 04:14 PM
hi xilus,

I cant see this window. How did you find these 2 windows ? selected the control and then tools -> ???

is this a problem in 2.1, i am yet to download 2.2.1 sdk

regards
Jagat

dejo
Mar 10, 2009, 04:57 PM
How did you find these 2 windows ? selected the control and then tools -> ???
Tools > Inspector. The first screenshot is from the Identity Inspector (⌘4) and the second one is from the Attributes Inspector (⌘1).

jagatnibas
Mar 22, 2009, 12:22 PM
Hi All,

I am still unable to find it.

I could see 3 things in nib file File's Owner, First Responder, View

dejo, I assume you had File's owner selected when u clicked tool->inspector

I used all the things like identity inspecotr and inspector i cannot find nibfile window [first figure]

I have attached this code, please help me. As long as the tableview is not mapped to MainViewController iboutlet var, it is fine, the moment it is connected, it gives key value pair error

please help

dejo
Mar 22, 2009, 03:15 PM
dejo, I assume you had File's owner selected when u clicked tool->inspector
I didn't. I hadn't tried it. I was just explaining how to bring up the Identity Inspector and Attributes Inspector.

eddietr
Mar 22, 2009, 05:04 PM
- (UIViewController *) initWithContacts: (NSArray *)importedConatcts {
UIViewController *viewController = [[UIViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
self.contacts = importedConatcts;
return viewController;
}


So this is the issue right here.

This is the initializer in MainViewController. So in this initialization, you should be setting up the MainViewController instance (which has already been alloc'ed) and then returning it.

Instead, what you are doing is allocating another controller of type UIViewController, and then initializing *that* and returning *that* controller instead of your instance of MainViewController.

And of course the UIViewController instance does not have a property called _contactsTableView, and so when initWithNibName loads your nib, it cannot set the _contactsTableView since that property and setter do not exist for a UIViewController. Therefore, you end up with the "this thing won't respond to my message to set this key/value" error.

Hope that helps.

jagatnibas
Mar 23, 2009, 04:40 AM
Thanks Eddie,

I kept on wondering around interface builder and forgot to review my own code, so stupid of me. How could I do this !


After this is solved, I foumd out another strange problem. I have contacts NSArray* member variable. and in initwithcontacts i am assigning contacts = importedcontacts. here when i debug i see correct items.

but when this contact is accessed in table callbacks it says nil and 0 number of items. I have tried a lot of things like using self.contacts, doing self.contacts = [[NSArray alloc] initwitharray:importedcontacts]

no avail.

Any solution that comes to your mind ?

I have been on and off from MAC and thats why keep forgetting things, sorry for being silly

regards
Jagat

jagatnibas
Mar 23, 2009, 07:20 AM
- (UIViewController *) initWithContacts: (NSArray *)importedConatcts {
MainViewController *viewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
viewController.contacts = importedConatcts;
return viewController;
}

i did this and it solved the problem. but i dont understand whats the difference between self.contacts and viewController.contacts

regards
Jagat

guetux
Aug 11, 2010, 07:18 AM
Thank you guys sooooo much! Just found this thread by google and it helped me with a problem i've been fighting for days now!!! Keep on rocking

Vlade
Apr 21, 2011, 04:36 PM
This was the first thread I found while searching for a solution to the problem, so here is some info that may help someone else. More likely than not it's the other solution listed, but in case anyone is doing something similar to me here is what I found.

To share a view controller with the Mac and iOS versions of one of my projects I did stuff like this

#if TARGET_OS_IPHONE
typedef UIWindow NSUIWindow;
#else
typedef NSWindow NSUIWindow;
#endif
then
IBOutlet NSUIWindow *mainWindow;

Interface Builder doesn't follow the typedefs correctly and even though it compiled it failed to launch. IB Does however follow this correctly

#define NSUIWindow UIWindow

Funny thing is I ran into this problem with two projects a year apart, and forgot the solution in between. Not sure why it worked in the first place, but it's frustrating when a project just crashes after not touching it for 6 months! Now all my game UI are in a custom OpenGL class I wrote, much easier!

symmetric
Nov 5, 2011, 05:12 PM
I just wasted several hours with this problem. The cause was a little different so I thought I'd post it. Although it turned out to be simple (and in hind sight seems obvious), it was a bear to find!:

I had a bunch of IBOutlets defined for my UITableViewController subclass. Through the course of development, some of them weren't being used anymore, but they were still connected to unused fields in the table view. When these unused properties were commented out it caused this error because the storyboard/view controller was still looking for properties that didn't exist any more.

The solution, of course, was just to remove the unused connections/fields from the storyboard.

rgeade
Dec 17, 2011, 10:52 PM
I just wasted several hours with this problem. The cause was a little different so I thought I'd post it. Although it turned out to be simple (and in hind sight seems obvious), it was a bear to find!:

I had a bunch of IBOutlets defined for my UITableViewController subclass. Through the course of development, some of them weren't being used anymore, but they were still connected to unused fields in the table view. When these unused properties were commented out it caused this error because the storyboard/view controller was still looking for properties that didn't exist any more.

The solution, of course, was just to remove the unused connections/fields from the storyboard.

This is exactly what my problem was. I had tested my app on several devices and on the sim and had no issues and submitted to the app store. After it posted, a relative showed me that it crashed at launch on his iPad 1 on iOS 3.2.1. Sure enough, it was because of old, unused connections in IB. It's weird that this didn't cause a problem on newer devices/OS levels. I am not exactly sure if it was the OS level, or the iPad 1 hardware, but it's fixed now!