xcode 如何将 Storyboard UIViewController 与我的自定义 UIViewController 类相关联?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32176189/
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 07:43:11  来源:igfitidea点击:

How do I associate a Storyboard UIViewController with my custom UIViewController class?

iosobjective-ciphonexcodeuiviewcontroller

提问by thecodingmate

I'm running Xcode 7 beta 5 and I have a storyboard with a tab bar controller featuring 4 items. Each item is a UIViewController. I created a custom class that is a subclass of UIViewController.

我正在运行 Xcode 7 beta 5,并且我有一个带有标签栏控制器的故事板,其中包含 4 个项目。每个项目都是一个 UIViewController。我创建了一个自定义类,它是 UIViewController 的子类。

When I go to the storyboard, click on one of the UIViewControllers, go to the Identity Inspector, click on custom class, and try to name my custom class it says,

当我转到故事板时,单击 UIViewControllers 之一,转到身份检查器,单击自定义类,然后尝试将我的自定义类命名为它,

"Launch screens may not set custom classnames"

Am I doing something wrong? I thought this was the way to associate a storyboard's UIViewController with your custom view controller.

难道我做错了什么?我认为这是将故事板的 UIViewController 与您的自定义视图控制器相关联的方法。

回答by Daumantas Versockas

The problem is that you are trying to assign a custom class to launch screen. Launch screens main function is to display a view until application loads (not to implement application logic). You should create a new view controller representing object in storyboard (this one should be displayed after application load) and assign a custom class to it.

问题是您正在尝试为启动屏幕分配一个自定义类。启动屏幕的主要功能是在应用程序加载之前显示视图(不是实现应用程序逻辑)。您应该在故事板中创建一个表示对象的新视图控制器(这个应该在应用程序加载后显示)并为其分配一个自定义类。

回答by JonEasy

As the error message says, custom classes are now forbidden in Launch Screens in Xcode 7. See e.g. hereas well

由于错误消息指出,自定义类现在禁止在在Xcode 7.请参阅启动画面,例如在这里以及

回答by Rohit Kumar

If you are trying to customize your Splash Screen then you can create your first view controller as Splash Screen and then set a custom class there.

如果你想自定义你的启动画面,那么你可以创建你的第一个视图控制器作为启动画面,然后在那里设置一个自定义类。

To tell the system that not to load launch screen just change the settings as mentioned below...

要告诉系统不要加载启动屏幕,只需更改如下所述的设置...

General Tab --> Launch Screen File --> Select "Main" (Basically it's Main Storyboard).

常规选项卡 --> 启动屏幕文件 --> 选择“主”(基本上是主故事板)。

回答by UsamaMan

This worked for me. I deleted LaunchScreen.storyboard and in main.storyboard I added the custom class which did not give any error later. Hope it helps someone else too.

这对我有用。我删除了 LaunchScreen.storyboard 并在 main.storyboard 中添加了自定义类,该类后来没有出现任何错误。希望它也能帮助别人。

回答by sleepwalkerfx

You can set a custom class to any storyboard component except the launchscreen.xib file.

您可以将自定义类设置为除 launchscreen.xib 文件之外的任何故事板组件。