ios 启动屏幕可能不会设置自定义类名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37764156/
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
Launch screens may not set custom classnames
提问by Genfood
I tried to add a custom class to my Table View Cell, but after I added it it gives the following error:
我试图向我的表格视图单元格添加一个自定义类,但是在我添加它之后它给出了以下错误:
I often read that I can't use custom classes in the LaunchScreen but I haven't touched this file. Can anyone help me?
我经常读到我不能在 LaunchScreen 中使用自定义类,但我没有接触过这个文件。谁能帮我?
This are my general settings for the main and the launch interface.
这是我对主界面和启动界面的常规设置。
I am using Swift.
我正在使用 Swift。
回答by Paulw11
回答by Honey
iOS 13 note:
iOS 13 注意:
Prior to iOS 13, you had both:
在 iOS 13 之前,您同时拥有:
Main.storyboard
LaunchScreen.storyboard
Main.storyboard
LaunchScreen.storyboard
Starting from iOS 13 by default you have SwiftUI. As a result you no longer have the Main.storyboard
. You only have LaunchScreen.storyboard
.
默认情况下,从 iOS 13 开始,您拥有 SwiftUI。因此,您不再拥有Main.storyboard
. 你只有LaunchScreen.storyboard
.
As for their differences see here
至于他们的区别,请看这里
And perhaps like me, you just saw the word storyboard and jumped right at it and later realized you're not building against Main.storyboard.
也许和我一样,你刚看到 storyboard 这个词就直接跳了进去,后来意识到你不是在构建Main.storyboard。
The fix is simple and is mentioned in Paulw11 answer
修复很简单,在Paulw11 回答中提到
Why that has happened?
为什么会这样?
It's because SwiftUI has somewhat deprecated the need of storyboards and tends to put focus on using previews as a single source of truth.
这是因为 SwiftUI 在某种程度上不赞成使用故事板,并且倾向于将重点放在使用预览作为单一事实来源上。
If you still want to work with the storyboard then what you have to do is upon creating the project set the 'User Interface' to 'Storyboard':
如果您仍然想使用故事板,那么您必须在创建项目时将“用户界面”设置为“故事板”:
回答by Bishal Ghimire
I always have a separate splash screen which is the first view controller app loads.
我总是有一个单独的启动画面,这是第一个视图控制器应用程序加载。
This is the file where you want to add all the business logical or display spinner / loader etc.
这是您要添加所有业务逻辑或显示微调器/加载器等的文件。
For this to work you have to setup Deployment target of your project as shown.
Note that you can not add any other custom class to LaunchScreen
. It is an ViewController to just show while app is about to start. In this phase of app life cycle nothing has yet been started. Its almost similar to static image ( It used to be only static image till iOS7 ). Starting for iOS9 or XCode 7 only it was changed to storyboard previously it used to be XIB file. Hence you can not add custom class objects to LaunchScreen
as this is a phase where app is still to be loaded or started.
请注意,您不能将任何其他自定义类添加到LaunchScreen
. 它是一个 ViewController,用于在应用程序即将启动时显示。在应用程序生命周期的这个阶段,还没有开始。它几乎类似于静态图像(它曾经只是静态图像,直到 iOS7 )。仅从 iOS9 或 XCode 7 开始,它已更改为故事板,以前它曾经是 XIB 文件。因此,您不能向其中添加自定义类对象,LaunchScreen
因为这是一个仍需加载或启动应用程序的阶段。
回答by William T.
To add on to Yash's comment, this error is misleading. If the Custom Class field is empty for your ViewController then you should also check every object on your view and see if their custom classes are empty as well, you can't even have a custom label set for the Launch Page.
补充一下 Yash 的评论,这个错误具有误导性。如果您的 ViewController 的 Custom Class 字段为空,那么您还应该检查视图上的每个对象并查看它们的自定义类是否也为空,您甚至无法为 Launch Page 设置自定义标签。
This is what got me and took me a while to figure out, had a custom class set on one of my labels by accident from a cut + paste.
这就是让我花了一段时间才弄清楚的原因,因为剪切 + 粘贴而意外地在我的一个标签上设置了自定义类。
回答by Honey
回答by JobLess
There are many reasons for this error.
导致此错误的原因有很多。
I got this error because launchscreen.storyboard and main.storyboard had same custom class as "viewController.swift".
我收到此错误是因为 launchscreen.storyboard 和 main.storyboard 具有与“viewController.swift”相同的自定义类。
Try removing the custom class from launchscreen.storyboard.
尝试从 launchscreen.storyboard 中删除自定义类。
回答by makhiye
Go to your -> launchScreen.storyboard then got to your -> identity and types -> uncheck the box -> use as launch Screen. Changing it in General -> App Icons and Launch images -> Launch Screen File drop down -> LaunchScreen instead of launchScreen.storyboard won't help(stop) do the above. make sure all your constraints are set properly easier way just copy the constraint settings from your main story board.
转到您的 -> launchScreen.storyboard,然后转到您的 -> 身份和类型 -> 取消选中该框 -> 用作启动屏幕。在 General -> App Icons and Launch images -> Launch Screen File 下拉菜单中更改它 -> LaunchScreen 而不是 launchScreen.storyboard 不会帮助(停止)执行上述操作。确保您的所有约束都设置得更简单,只需从主故事板复制约束设置即可。