0

I've inherited an iOS project, which is running in production, but I'm getting the following exception when I try to run it:

Unknown class TabBarTestAppDelegate in Interface Builder file.
2015-02-26 16:26:34.281 MyApp[1197:435870] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UICustomObject 0x17e4efe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key MainViewController.'

It's linked via the lib file as shown in the following image

MainWindow.xlb

The code for the header is as follows:

@interface TabBarTestAppDelegate : NSObject <UIApplicationDelegate> {

    //IBOutlet UIViewController *MainViewController;
    UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

And at the start of the application as follows:

#import "TabBarTestAppDelegate.h"
#import "ZBarSDK.h"
#import "MainViewController.h"

NSString* defaultPlistName = @"DefaultConfig";
@implementation TabBarTestAppDelegate

@synthesize window;

#pragma mark -
#pragma mark Application lifecycle



- (void)applicationDidFinishLaunching:(UIApplication *)application 
{    


    //self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    //self.window.backgroundColor = [UIColor whiteColor];
    //[self.window makeKeyAndVisible];


    // Override point for customization after app launch
    //[mainViewController viewWillAppear: YES];
    //[window addSubview: mainViewController.view];
    //[mainViewController.view removeFromSuperview];
    //mainViewController.managedObjectContext = self.managedObjectContext;

    //Old implementaion
    //[window makeKeyAndVisible];

    //MainViewController* mainView = [[MainViewController alloc]initWithNibName:@"MainView" bundle:nil];

    //[self.window addSubview:mainView.view];
    //[self.window makeKeyAndVisible];
}

Here is the calling code:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

Here's the stack trace:

2015-02-26 17:46:38.584 MyApp[1229:443617] Unknown class TabBarTestAppDelegate in Interface Builder file.
2015-02-26 17:46:38.597 MyApp[1229:443617] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UICustomObject 0x145b24e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key MainViewController.'
*** First throw call stack:
(0x2bf955f7 0x39807c77 0x2bf95305 0x2cbfeb55 0x2cc10e23 0x2bee52e3 0x2f7f7801 0x2f7f911f 0x2f69c5a3 0x2f69b94b 0x2f6a62f9 0x2f69a2eb 0x3270b0c9 0x2bf5bffd 0x2bf5b2c1 0x2bf59e1b 0x2bea6b31 0x2bea6943 0x2f49e127 0x2f498f21 0x4d04f 0x382d0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

I've checked a lot of similar messages, but many of them seem to apply to Xcode 6 and converting from storyboard. I also get this exception when running from Xcode 5 on a different system. Any ideas how to fix this?

Jack BeNimble
  • 35,733
  • 41
  • 130
  • 213
  • Can you post the full stack trace and the corresponding code? – Bot Feb 26 '15 at 22:29
  • I wonder why the TabTestBarAppDelegate is an app delegate in the first place - there is another AppDelegate in the project already. I'm guessing the flow is AppDelegate, which brings up the MainWindow, which brings up the TabTestBarAppDelegate. I guess the main question is why the project, or the xib file specifically, doesn't see the TabTestBarAppDelegate. – Jack BeNimble Feb 27 '15 at 19:18
  • I think the problem was that I needed to connect the TabBarTestAppDelegate to the FileOwner. Of course, now I'm getting a "Class not found" error, but that's a different problem. – Jack BeNimble Feb 27 '15 at 20: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:20

1 Answers1

0

The answer was to select the target, build phases, compile sources and add the TabTestBarAppDelegate.m file. I had tried that, but it had led to a "duplicate object" message from the clang compiler. It turned out the the "duplicate object" was another app delegate that the previous developer had been trying to use (which wasn't working). So when I deleted that from the compile sources, it worked.

Jack BeNimble
  • 35,733
  • 41
  • 130
  • 213