0

Problem:

  • I am getting a following error on Button click:

2014-06-05 13:19:28.118 Generic-Project[277:60b] Unknown class MySecondViewController in Interface Builder file.

2014-06-05 13:19:28.134 Generic-Project[277:60b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key lblStatus.'

Supporting comments:

  • lblStatus is a UILabel inside the new view controller which I am trying to open on button click. The custom class of the view controller is correct and the this label is only connected to the following property in the new view controller:

    @property (weak, nonatomic) IBOutlet UILabel *lblStatus;
    

Connections:

  • Just a note, all the View Controllers including the root view controller is in a library that we've created. And the storyboard is in a different project. I've added the library reference to Linked Framework and Libraries option in General settings of the project in order to tell the project to use the library. Root view controller shows fine but when I click the button on it to open the second view controller, it gives the error.

  • All works fine if either I move the second view controller from the library to the project or if I just add the .m file from the library to the Compile Sources in Build Phases of the project.

What I've tried:

I've tried the answers on following:

I'll appreciate your input. I am a beginner in iOS and have been trying to solve the puzzle since a day.

Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
  • This sounds like an XIB / IBOutlet problem. Are you certain that your UILabel is hooked up correctly in the XIB? Double/Triple check your View Controller Files Owner's connections and make sure there are no broken connections. – Aaron Jun 05 '14 at 17:55
  • @Aaron Thanks for quick response. I've added a snapshot of the connections. It looks fine to me. Can you let me know if anything is missing there? Thanks again. – Shobhit Puri Jun 05 '14 at 18:15
  • 1
    Sounds like -ObjC flag link issue to me, ie [this problem](http://stackoverflow.com/questions/1725881/unknown-class-myclass-in-interface-builder-file-error-at-runtime) or [mention here](https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/configuration.html#//apple_ref/doc/uid/TP40012554-CH3-SW2) "This flag will tell the linker to link all Objective-C classes and categories from static libraries into your application, even if the linker can’t tell that they are used. " – stevesliva Jun 05 '14 at 22:16
  • Thanks @stevesliva for pointing that out. That was the whole issue. You explained it well. Plz post that as an answer; it might help the starters like me. – Shobhit Puri Jun 09 '14 at 14:56

1 Answers1

1

You need to use the -ObjC flag in "Other Linker Flags" in the project's Build Settings. This gets the linker to build everything in the library.

It is mentioned in the Apple static library how-to which says:

This flag will tell the linker to link all Objective-C classes and categories from static libraries into your application, even if the linker can’t tell that they are used.

stevesliva
  • 5,351
  • 1
  • 16
  • 39