Search code examples
iosinterface-builderxibxcode7iboutlet

iOS xib file IBOutlet not recognized - (class not key-value coding compliant)


I am running XCode 7.1 and running on device(iOS 9) - (not simulator). I am loading up a nib file by name as such:

MyDetailsViewController *myDetailsVC = [MyDetailsViewController initWithNibNamed:@"MyDetails" withNotificationCenter:notificationCenter];

this is simply just a class method that i have set up that loads up the xib via the mainBundle. The xib file is just a UIView with a tableview inside of it everything seems to be hooked up properly. However, when loading the nib(viewWillAppear, viewDidLoad etc hasn't executed yet) from the bundle I get the error:

NSUnknownKeyException, reason: '[MyDetailsViewController setValue:forUndefinedKey:]:This class is not key value coding-compliant for the key tableView'

I know that I am not getting back some generic view controller because it spells out very clearly what view controller we are talking about. The File Owner seems to be hooked up properly and its Custom Class is set to MyDetailsViewController. Even when I hover over the IBOutlet 'circle' in code the tableview highlights as well as when i hover over the menu when checking the outlets.

Something that may be totally unrelated is the internal error message in the xib file, it may or may not be related to my problem and i've never seen it before. The beginning of the log file that you get from that error is:

enter image description here

Can anyone help me determine what is going on here? I would appreciate it.

here are a few more screenshots:

enter image description here

enter image description here

enter image description here

enter image description here


Solution

  • Before init you should call alloc first:

    // MyDetailsViewController *myDetailsVC = [MyDetailsViewController initWithNibNamed:@"MyDetails" withNotificationCenter:notificationCenter];
    MyDetailsViewController *myDetailsVC = [[MyDetailsViewController alloc] initWithNibNamed:@"MyDetails" withNotificationCenter:notificationCenter];