【问题标题】:Tab Bar Controller in the second screen [duplicate]第二个屏幕中的标签栏控制器[重复]
【发布时间】:2012-12-09 09:21:29
【问题描述】:

可能重复:
UIAlertView crashes when added to app

我是 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 文件中,我选择 UIApplication 类作为“文件的所有者”和 AppDelegate - appdelegate 类。然后我将文件的所有者加入了应用程序委托。

当我运行我的应用并单击第一个视图上的按钮时,应用崩溃并出现以下错误: 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? 谢谢。

【问题讨论】:

  • 您是否创建了两次mainViewController?你的代码看起来像这样。

标签: ios xcode controller tabbar


【解决方案1】:

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

【讨论】:

  • 我的项目中根本没有任何警告。如果我删除文件所有者(UIApplication)和 AppDelegate 之间的链接,我的应用程序会崩溃并出现另一个异常:“[UIViewController _loadViewFromNibNamed:bundle:] 加载了“ViewController”笔尖,但未设置视图出口。'”
  • @BIB,所以您的 xib 中没有任何名为 delegate 的东西未在 viewcontroller 类中定义?
猜你喜欢
  • 2013-11-24
  • 2020-08-18
  • 2012-01-20
  • 1970-01-01
  • 1970-01-01
  • 2020-06-10
  • 1970-01-01
  • 2012-01-20
相关资源
最近更新 更多