this class is not key value coding-compliant for the key view.'

Adriana Carelli picture Adriana Carelli · Oct 4, 2012 · Viewed 11.5k times · Source

I have a problem in AppDelegate, when run the app I get this error:

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

This is the code of AppDelegate.h

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>{

        //UINavigationController *navigationController;
 }

@property (strong, nonatomic) UIWindow *window;


@property (copy, nonatomic) ViewController * viewController;
@property (copy, nonatomic) UINavigationController * navigationController;



 @end

This is the code of AppDelegate.m

 #import "AppDelegate.h"

 #import "RootViewController.h"



  @implementation AppDelegate



  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions
   {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        RootViewController *rootMenu;


         if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
              rootMenu= [[RootViewController alloc]  initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
              rootMenu = [[RootViewController alloc]initWithNibName:@"ViewController_iPad" bundle:nil];
  }


  self.navigationController =[[UINavigationController  alloc]initWithRootViewController:rootMenu];

  self.window.rootViewController = self.navigationController;

  [self.window makeKeyAndVisible];
   return YES;
 }

What can I do to resolve this error? I have rewritten the RootViewController, throwing in the trash the old one, but the problem remains the same.Thanks in advance

Answer

bgolson picture bgolson · Oct 4, 2012

This usually happens when an Interface Builder or Storyboard connection hasn't properly been made. Sometimes you'll make a connection, and then delete the code that the connection was made to. Interface Builder still has a reference to the code, which causes the key/value compliant run time error. You can also get this error if you haven't assigned the proper class to a view controller. If you've written code for a particular view controller, be sure to set the class appropriately in Interface Builder for that View Controller.