简体   繁体   English

Xcode:故事板改变初始视图控制器

[英]Xcode: Storyboard change initial view controller

I started my app with the "master-detail" template. 我使用“master-detail”模板启动了我的应用程序。 I simply added two other VCs and changed the "initial view controller" checkbox to "Safety Culture MainVC"...when I run, my app crashes... 我只是添加了另外两个VC并将“初始视图控制器”复选框更改为“Safety Culture MainVC”...当我运行时,我的应用程序崩溃了......

What do I need to do?! 我需要做什么?!

This is a screenshot of the default storyboard with my two other VCs thrown in--they work when the "Navigation Controller" is the default. 这是默认故事板的屏幕截图,其中两个其他VC被引入 - 当“导航控制器”是默认值时它们工作。

Clearly, I'm a beginner, so as much detail as you can give me is helpful!! 显然,我是初学者,所以尽可能多的细节给你带来帮助! Thanks! 谢谢!

故事板

Debug Output: 调试输出:

2012-06-07 10:38:42.812 SafetyCulture[1020:fb03] -[safetyCultureMainVC topViewController]: unrecognized selector sent to instance 0x6b7c210 2012-06-07 10:38:42.840 SafetyCulture[1020:fb03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[safetyCultureMainVC topViewController]: unrecognized selector sent to instance 0x6b7c210' * First throw call stack: (0x16ae022 0x183fcd6 0x16afcbd 0x1614ed0 0x1614cb2 0x2619 0x17386 0x18274 0x27183 0x27c38 0x1b634 0x1598ef5 0x1682195 0x15e6ff2 0x15e58da 0x15e4d84 0x15e4c9b 0x17c65 0x19626 0x22ed 0x2255) terminate called throwing an exception(lldb) 2012-06-07 10:38:42.812 SafetyCulture [1020:fb03] - [safetyCultureMainVC topViewController]:无法识别的选择器发送到实例0x6b7c210 2012-06-07 10:38:42.840 SafetyCulture [1020:fb03] *由于未被捕获而终止应用程序异常'NSInvalidArgumentException',原因是: ' - [safetyCultureMainVC topViewController]:无法识别的选择发送到实例0x6b7c210' *第一掷调用堆栈:(0x16ae022 0x183fcd6 0x16afcbd 0x1614ed0 0x1614cb2 0x2619 0x17386 0x18274 0x27183 0x27c38 0x1b634 0x1598ef5 0x1682195 0x15e6ff2 0x15e58da 0x15e4d84 0x15e4c9b 0x17c65 0x19626 0x22ed 0x2255)终止调用抛出异常(lldb)

topViewController is a method of a UINavigationController . topViewControllerUINavigationController一种方法。 You app tries to call this method and since it is not there it crashed. 你的应用程序试图调用此方法,因为它不存在它崩溃。

In your image your entry point arrow is still on the navigation controller: 在您的图像中,您的入口点箭头仍在导航控制器上:

在此输入图像描述

Move it via drag&drop to your safetyCultureMainVC like this: 通过拖放操作将其移动到您的safetyCultureMainVC如下所示: 在此输入图像描述

Your Initial View Controller needs to be embedded in something when you are in a storyboard. 当您在故事板中时,您的初始视图控制器需要嵌入到某些内容中。 For example, tab bar controller, navigation controller... 例如,标签栏控制器,导航控制器......

Judging from your workflow you posted, all your controllers should be part of the same navigation controller. 从您发布的工作流程来看,所有控制器都应该是同一导航控制器的一部分。 Starts with Safety Culture, then goes one of two paths depending on which button is pushed. 从安全文化开始,然后根据按下哪个按钮选择两个路径之一。

It should look like this: 它应该如下所示:

在此输入图像描述

For me, it was that I was doofishly accessing variables that were not set in my ViewDidLoad. 对我来说,就是我无法访问未在我的ViewDidLoad中设置的变量。 This new view was previously hooked up to a segue from another view, which had set the variables. 此新视图之前已连接到另一个视图的segue,该视图已设置变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM