CodeGuy
CodeGuy

Reputation: 28907

Xcode iPhone App error on launch: NSUnknownKeyException

What does this error mean exactly and how do I fix it?

2011-08-10 12:06:54.116 ScanTest[973:707] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ScanTestAppDelegate 0x190970> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navigationController.'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x36d0d64f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x33f66c5d objc_exception_throw + 24
    2   CoreFoundation                      0x36d0d3cd -[NSException dealloc] + 0
    3   Foundation                          0x3511eedb -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 182
    4   Foundation                          0x350d79cb _NSSetUsingKeyValueSetter + 90
    5   Foundation                          0x350d7217 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 194
    6   Foundation                          0x350b942f -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 130
    7   UIKit                               0x35cfd8df -[UIRuntimeOutletConnection connect] + 66
    8   CoreFoundation                      0x36ca5d7b -[NSObject(NSObject) performSelector:] + 18
    9   CoreFoundation                      0x36ca599d -[NSArray makeObjectsPerformSelector:] + 388
    10  UIKit                               0x35cfc847 -[UINib instantiateWithOwner:options:] + 586
    11  UIKit                               0x35cfde09 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 92
    12  UIKit                               0x35b284cd -[UIApplication _loadMainNibFile] + 96
    13  UIKit                               0x35b22b09 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 180
    14  UIKit                               0x35af77d7 -[UIApplication handleEvent:withNewEvent:] + 1114
    15  UIKit                               0x35af7215 -[UIApplication sendEvent:] + 44
    16  UIKit                               0x35af6c53 _UIApplicationHandleEvent + 5090
    17  GraphicsServices                    0x36431e77 PurpleEventCallback + 666
    18  CoreFoundation                      0x36ce4a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    19  CoreFoundation                      0x36ce683f __CFRunLoopDoSource1 + 166
    20  CoreFoundation                      0x36ce760d __CFRunLoopRun + 520
    21  CoreFoundation                      0x36c77ec3 CFRunLoopRunSpecific + 230
    22  CoreFoundation                      0x36c77dcb CFRunLoopRunInMode + 58
    23  UIKit                               0x35b21d49 -[UIApplication _run] + 372
    24  UIKit                               0x35b1f807 UIApplicationMain + 670
    25  ScanTest                            0x000037fb main + 70
    26  ScanTest                            0x00002e44 start + 40
)
terminate called after throwing an instance of 'NSException'

Here is my didFinishLaunching method in my app delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Override point for customization after app launch    
    UINavigationController *navigationController = [[UINavigationController alloc] init];
    [window addSubview:navigationController.view];

    MainViewController *viewController = [[MainViewController alloc] init];
    [navigationController pushViewController:viewController animated:NO];
    [viewController release];

    // Override point for customization after application launch
    [window makeKeyAndVisible];
    return YES;
}

Upvotes: 0

Views: 412

Answers (3)

Solid Soft
Solid Soft

Reputation: 1932

your code write like this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Override point for customization after app launch    

    MainViewController *viewController = [[MainViewController alloc] init];

    UINavigationController *navigationController = [[UINavigationController alloc] init];

    [navigationController pushViewController:viewController animated:NO];
    [viewController release];

    [window addSubview:navigationController.view];


    // Override point for customization after application launch
    [window makeKeyAndVisible];
    return YES;
}

now this works..

Upvotes: 0

FeifanZ
FeifanZ

Reputation: 16316

Your MainWindow.xib is missing an outlet for navigationController, even though it's still being connected. Either re-add the IBOUtlet to your AppDelegate.h, or disconnect the outlet from the XIB.

Upvotes: 1

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

This means that your MainWindow.xib is trying to attach an outlet navigationController to the app delegate. You must have removed the outlet after setting up the xib.

Upvotes: 1

Related Questions