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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10933780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:31:42  来源:igfitidea点击:

Xcode: Storyboard change initial view controller

iosxcodestoryboard

提问by Kevin Brown

I started my app with the "master-detail" template. I simply added two other VCs and changed the "initial view controller" checkbox to "Safety Culture MainVC"...when I run, my app crashes...

我使用“master-detail”模板启动了我的应用程序。我只是添加了另外两个 VC 并将“初始视图控制器”复选框更改为“安全文化 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!

显然,我是一个初学者,所以你能给我的尽可能多的细节是有帮助的!!谢谢!

Storyboard

故事板

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.812由于应用程序安全性 [1020:812]异常'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)

回答by Pfitz

topViewControlleris a method of a UINavigationController. You app tries to call this method and since it is not there it crashed.

topViewController是 a 的一种方法UINavigationController。您的应用程序尝试调用此方法,但由于它不在那里,因此崩溃了。

In your image your entry point arrow is still on the navigation controller:

在您的图像中,您的入口点箭头仍在导航控制器上:

enter image description here

在此处输入图片说明

Move it via drag&drop to your safetyCultureMainVClike this: enter image description here

通过拖放将其移动到您safetyCultureMainVC像这样: 在此处输入图片说明

回答by Mike Z

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:

它应该是这样的:

enter image description here

在此处输入图片说明

回答by ALamp

For me, it was that I was doofishly accessing variables that were not set in my ViewDidLoad. This new view was previously hooked up to a segue from another view, which had set the variables.

对我来说,这是我愚蠢地访问未在我的 ViewDidLoad 中设置的变量。这个新视图以前连接到另一个视图的 segue,它设置了变量。