0

可能重复:
添加到应用程序时 UIAlertView 崩溃

我是 Objective-C 和 Xcode 的新手。在我的应用程序中,第一个屏幕是一个视图控制器和一个按钮。我想在按下该按钮时显示标签栏,因此标签栏将成为第二个屏幕。

这是我正在尝试做的事情:

appdelegate.h

@property (strong, nonatomic) FirstViewController *viewController1;

appdelegate.m

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     self.viewController1 = [[FirstViewController alloc]
     initWithNibName:@"FirstViewController" bundle:nil];
     self.window.rootViewController = self.viewController1;
     [self.window makeKeyAndVisible];
     return YES; }

在我FirsViewController.m有按钮点击事件:

 -(IBAction) showMainView:(id) sender{  
     ViewController *mainViewController = [[ViewController alloc] initWithNibName:@"ViewController"
                                                                           bundle:nil];
     [self.view addSubview:mainViewController.view];
     mainViewController = [[ViewController alloc] initWithNibName:@"ViewController"                          
                                                           bundle:nil];
     [self.view addSubview:mainViewController.view];

ViewController 是一个带有标签栏的 xib。

在 IB 的第二个 xib 文件中,我为“文件的所有者”和 AppDelegate - appdelegate 类选择了 UIApplication 类。然后我加入了文件的所有者和应用程序委托。

当我运行我的应用程序并单击第一个视图上的按钮时,应用程序崩溃并出现以下错误: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x744f0f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'

你能告诉我如何克服这个问题吗?可能是在单击按钮后我应该将 tabbarController 重新分配为rootViewController?谢谢。

4

1 回答 1

0

错误消息看起来像,您在 xib 中设置了一些名为delegate未正确连接到类文件(ViewController)的东西。检查您的 xib 是否显示一些警告消息并将其删除或修复该问题。

于 2012-12-09T10:17:33.467 回答