Interface Builder文件中的未知类;由于未捕获的异常'NSUnknownKeyException'而终止应用

时间:2015-02-26 21:45:46

标签: ios xcode xib iboutlet

我继承了一个正在生产中运行的iOS项目,但是当我尝试运行它时,我遇到了以下异常:

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.'

它通过lib文件链接,如下图所示

MainWindow.xlb

标题的代码如下:

@interface TabBarTestAppDelegate : NSObject <UIApplicationDelegate> {

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

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

@end

在应用程序开始时如下:

#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];
}

这是调用代码:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

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

这是堆栈跟踪:

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) 

我检查了很多类似的消息,但其中许多似乎适用于Xcode 6并从故事板转换。在不同系统上从Xcode 5运行时,我也会遇到此异常。任何想法如何解决这一问题?

1 个答案:

答案 0 :(得分:0)

答案是选择目标,构建阶段,编译源并添加TabTestBarAppDelegate.m文件。我试过了,但它导致了一个重复的对象&#34;来自clang编译器的消息。结果发现了重复的对象&#34;是另一个应用程序代表,以前的开发人员一直在尝试使用(它没有工作)。所以当我从编译源删除它时,它工作。