RootViewController is not key value coding-compliant

Discussion in 'iOS Programming' started by danielpunt, Sep 4, 2008.

  1. macrumors newbie

    Joined:
    Oct 11, 2007
    Location:
    Netherlands
    #1
    I have a RootViewController which loads another view called MainViewController like this:

    Code:
    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 :
    Code:
    '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. :)
     
  2. macrumors newbie

    Joined:
    Sep 2, 2008
    #2
    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
     
  3. macrumors newbie

    Joined:
    Dec 12, 2007
    #3
    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.'
     
  4. macrumors newbie

    Joined:
    Dec 12, 2007
    #4
    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.
     
  5. macrumors newbie

    Joined:
    Mar 5, 2009
    #5
    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
    [​IMG]
    AND ALSO.. the nib name here
    [​IMG]
     
  6. macrumors regular

    Joined:
    Jul 28, 2008
    #6
    where is it ?

    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
     
  7. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Tools > Inspector. The first screenshot is from the Identity Inspector (⌘4) and the second one is from the Attributes Inspector (⌘1).
     
  8. macrumors regular

    Joined:
    Jul 28, 2008
    #8
    scratching my head -- gone mad

    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
     

    Attached Files:

  9. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    I didn't. I hadn't tried it. I was just explaining how to bring up the Identity Inspector and Attributes Inspector.
     
  10. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #10
    Code:
    - (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.
     
  11. macrumors regular

    Joined:
    Jul 28, 2008
    #11
    Thanks

    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
     
  12. macrumors regular

    Joined:
    Jul 28, 2008
    #12
    got it

    - (UIViewController *) initWithContacts: (NSArray *)importedConatcts {
    MainViewController *viewController = [[MainViewController alloc] initWithNibName:mad:"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
     
  13. macrumors newbie

    Joined:
    Aug 11, 2010
    #13
    Huge Thank You

    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
     
  14. macrumors 6502a

    Vlade

    Joined:
    Feb 2, 2003
    Location:
    Meadville, PA
    #14
    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

    Code:
    #if TARGET_OS_IPHONE
    typedef UIWindow NSUIWindow;
    #else
    typedef NSWindow NSUIWindow;
    #endif
    then
    Code:
    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

    Code:
    #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!
     
  15. macrumors newbie

    Joined:
    Nov 5, 2011
    #15
    Sigh, sometimes I hate Xcode's error messages!

    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.
     
  16. macrumors newbie

    Joined:
    Sep 30, 2009
    #16
    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!
     

Share This Page