4

The full error is: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key.

So I have been trying what other people have been saying with similar problems. I have tried getting rid of every mention of landscapeView in the project, including the Connections in the FIle's Owner in the ViewController_iPhone.xib and then I started fresh by making outlets in the super class ViewController (since I want to use landscapeView and portraitView for iPad also) then I set up connections in ViewController_iPhone.xib and ViewController_iPad.xib to the UIView named Landscape in each respectively, and I still get this error.

I'm just starting out in app development so I'm trying to make a template for an app that is supportive of all orientations on both iPhone and iPad. Thanks for any help

EDIT: Here is a link to all my app delegate h and m and main.m : I am getting the Applications are expected to have a root view controller at the end of application launch error

EDIT 2: So I also tried to make landscapeView a property of ViewController and I made a setter method in ViewController.m but it still has the same problem.

Community
  • 1
  • 1
Peter P
  • 289
  • 1
  • 5
  • 17
  • Without at least a stack trace or really anything substantive that's specifically about your program, it's going to be very difficult for anyone to respond constructively. Also, where does landscapeView enter into it? – zmccord Mar 08 '12 at 03:22
  • The error you are getting means you are trying to set a value that with a key that doesnt exist. where in your code are you setting a value with a key ? – Pochi Mar 08 '12 at 03:23
  • Ok so @zmccord where will I find the stack trace? And is there anything else I can link? – Peter P Mar 08 '12 at 04:29
  • Ok so @zmccord where will I find the stack trace? And is there anything else I can link? And at Luis Oscar I don't know I've been trying to find that, because I kind of understand what is going wrong but I don't know where it is going wrong, the main function in main.m pops up green when I run the program. I have ran search on my project for the word "key" and it pops up twice in a comment and in AppDelegate.m in the [self.window makeKeyAndVisible]; line inside of the didFinishLaunchingWithOptions function. – Peter P Mar 08 '12 at 04:36
  • possible duplicate of [What does this mean? "'NSUnknownKeyException', reason: ... This class is not key value coding-compliant for the key X"](http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key) – jtbandes Aug 03 '15 at 06:22

4 Answers4

10

I've found the most common place this error happens is when you instantiate a view from a xib from within a class that is not the xib's owner.

What I mean by this is you might be calling something similar to this:

[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];

You're changing the owner, so you have to be sure that the class that self refers to has all the IBOutlet properties needed by "MyView". Usually this is done in Interface Builder, but in this case you're setting your owner programmatically, which means you can't make the connections in IB. When the IBOutlets aren't there, the app tries to make those connections and fails, giving the error you see.

My advice (without knowing any more info than you've given so far) is to check to see if you've made this call without having the proper IBOutlets.

Aaron
  • 6,988
  • 4
  • 31
  • 48
  • Aaron is there a way I can send you my project, but I have done not very much from the basic SIngle View project that is for all devices. I just made 2 subclasses of ViewController, then made the UIView objects in both xibs then made then the properties in IB so the code was generated automatically, I made the 2 xibs Fle Owner's classes the correct subclasses, and I went the the Info tab made the Status bar not appear initally and choose the main nib file and the main nib file (ipad) to be the two xib files. – Peter P Mar 08 '12 at 22:29
  • And in my appdelegate.m I changed the applicationDidFinishLaunchingWithOptions by changing [ViewController alloc] to [ViewController_iPhone alloc] and [ViewController_iPad alloc], and i wrote import the two subclasses. – Peter P Mar 08 '12 at 22:30
  • Thanks the iPhone Developer Forums Got my question, was a mixture of certain functions overriding and templates that caused the error – Peter P Mar 09 '12 at 05:53
  • Glad you got your answer. Sorry I wasn't around to look at your code sooner. – Aaron Mar 09 '12 at 15:30
8

I had to remove the NIB or XIB (or whatever they are this iteration) for the Main Interface.

It sure would be nice if Apple fully tested the broken software before unleashing it on the unsuspecting public. They could have handled the problem in any number of ways; but instead they chose a runtime crash and obscure [meaningless] error message.

enter image description here

jww
  • 97,681
  • 90
  • 411
  • 885
1

Two main reason is follow

  1. your iboutlet may break please check in storyboard or IB.
  2. if you don't select module for custom class, see into your storyboard.
Ravi Kumar
  • 1,356
  • 14
  • 22
0

What I found is I deleted a WebView in viewcontroller.h , but haven't delete the xib file that point to this WebView !

idea2real
  • 71
  • 6