当前位置: 首页 > 知识库问答 >
问题:

为什么这个故事板没有实例化?

宋奇希
2023-03-14

我完全是以编程的方式在iOS中工作,也完全是使用IB,但我第一次尝试将两者混合使用,我感到困惑。我正在写一个标签应用程序。在我的应用程序委托中,我曾经有以下代码:

//...Code setting view controllers for various tab items and then this...

GHSettingsViewController *svc = [[GHSettingsViewController alloc] init];
svc.tabBarItem.title = @"Settings";
svc.tabBarItem.image = [UIImage imageNamed:@"20-gear-2.png"];
[tabItems addObject:svc];

那很好。

然后,我通过IB中的故事板创建了一个视图控制器,并向其添加了一堆用户界面元素,给出了以下设置:

现在我的代码是:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
GHSettingsViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"settings"];
svc.tabBarItem.title = @"Settings";
svc.tabBarItem.image = [UIImage imageNamed:@"20-gear-2.png"];
[tabItems addObject:svc];

应用程序可以正常启动,但当我按tab键进入设置屏幕时,会收到以下消息:

这意味着什么?我如何修复它?

编辑:这里是一个完整的版本的代码从应用程序委托在didFinishLaunting:{self.window=[[UIWindow alloc]initBackFrame:[[UIScreen主屏幕]边界]];[self.windowmakeKeyAndViable];

NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:5];

GHHaikuViewController *hvc = [[GHHaikuViewController alloc] init];
hvc.tabBarItem.title = @"Home";
hvc.tabBarItem.image = [UIImage imageNamed:@"53-house.png"];
[tabItems addObject:hvc];

GHComposeViewController *cvc = [[GHComposeViewController alloc] init];
cvc.tabBarItem.title = @"Compose";
cvc.tabBarItem.image = [UIImage imageNamed:@"216-compose.png"];
[tabItems addObject:cvc];

GHWebViewController *wvc = [[GHWebViewController alloc] init];
wvc.tabBarItem.title = @"Buy";
wvc.tabBarItem.image = [UIImage imageNamed:@"80-shopping-cart.png"];
[tabItems addObject:wvc];

GHFeedback *fvc = [[GHFeedback alloc] init];
fvc.tabBarItem.title = @"Feedback";
fvc.tabBarItem.image = [UIImage imageNamed:@"18-envelope.png"];
[tabItems addObject:fvc];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
//UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard.storyboard" bundle:nil]; //Using this instead causes the application to crash on launching.
GHSettingsViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"settings"]; 
//GHSettingsViewController *svc = [storyboard instantiateInitialViewController]; //Using this instead of the line above causes the same error.
svc.tabBarItem.title = @"Settings";
svc.tabBarItem.image = [UIImage imageNamed:@"20-gear-2.png"];
[tabItems addObject:svc];

GHTabBarController *tbc = [[GHTabBarController alloc] init];
tbc.viewControllers = tabItems;
self.window.rootViewController = tbc;

return YES;

}

共有1个答案

连德义
2023-03-14

看起来您正在UITabBarController内部使用这个新的UIViewController。在应用程序:didFinishLaunchingAnd Options:中,按原样创建新的UIStoryboard。然后创建一个UIViewController实例

UIViewController *viewController = [storyboard instantiateInitialViewController]; 

然后,只需将viewController添加到UITabBarControllerviewControllers数组中。

我不确定tabItems的用途,但您需要将视图控制器添加到选项卡栏的viewControllers数组中。

更新:从我们在聊天中的讨论中,故事板中引用了一个额外的IBOutlet,它实际上没有连接起来,导致了崩溃。点击调试导航器中的“继续”按钮给了我们一些额外的信息,并导致了这个问题。

 类似资料:
  • 我尝试了一切,但图像不会显示出来,我试图使图像变小但没有用,我试图改变路径,我试图改变图像的位置但没有帮助,我试图在互联网上搜索但一无所获。 我看到的只是空白的图形用户界面,没有文本和图像。如果你能帮我,你会帮我一个大忙。 代码如下:

  • 我对这个代码有问题。 当单击tableView中的单元格时,应运行此代码。然而什么也没发生。据我所知,UIViewController根本没有创建。上面的代码放在这里。 ProfileViewController类型是这样定义的。 我甚至尝试在之前添加并删除中之前的,但都不起作用。我在某处读到viewController需要在方法中才能创建,并尝试将其放在那里(没有成功,引发了一个致命错误)。 我

  • 我是否遗漏了包装类中的某些细节? 我有以下程序,在其中我定义了一个类,它包装并提供运算符: 我以为这会编译成同样的东西--它在做同样的计算,所有的东西都是内联的。 编辑-如果我使用而不是,它将产生相同的输出。 编辑-我发布了错误的ASM版本(而不是),因此本节没有帮助。 我在我的Mac电脑上使用Xcode的gcc,在一个64位系统上。除了for-loop的主体之外,结果是相同的。

  • 我有一个Spring Boot 2.1.6应用程序(Spring 5),我想使用Thymeleaf作为我的模板引擎。我按照在线教程来设置我的项目,视图和控制器,当我想启动它时,我注意到Thymeleaf抱怨说它找不到任何模板: 我想我设置的项目,因为它应该是(至少根据教程和论坛,我可以找到): 我的控制器如下所示: login.html是这样的: 当我打开登录页面时,我得到一个简单的超文本标记语言

  • 在JavaScript中,我按住两个键,并且被完美触发。当我释放其中一个键时,被触发。到目前为止一切都很好。但是我仍然按住一个键,那么为什么没有被触发呢?我需要在我的游戏中发生这种情况。我做错了什么吗?这是预期的反应吗?有什么解决办法吗?

  • 为什么x没有在下面初始化? 平均而言,对于一半的迭代,for循环中的将是,从而初始化。对于另一半,找到的 循环替换为 同样糟糕。只有