How to access both Objective-C and Swift classes from same storyboard?(如何从同一个故事板访问 Objective-C 和 Swift 类?)
问题描述
我已经在 Swift 中实现了一个 UIButton 派生类(RoundButton),其余的仍在 Objective-C 中.如何在同一个 Storyboard 中同时访问基于 Objective-C 的类和基于 Swift 的类?
I have implemented one UIButton-derived class (RoundButton) in Swift and the rest is still in Objective-C. How do I access both Objective-C-based classes and Swift-based classes in the same storyboard?
您可以在 Storyboard 的 UIButton Custom Class - Class
字段中键入 RoundButton
,但 iOS 会给出以下警告运行时:
You can type RoundButton
in a UIButton Custom Class - Class
field in a Storyboard, but iOS gives the following warning runtime:
Unknown class RoundButton in Interface Builder file.
推荐答案
看来Xcode 6.0 (6A215l) 需要将Storyboard 文件升级到更新版本才能访问Swift 类.
It seems that Xcode 6.0 (6A215l) needs to upgrade the Storyboard file to a newer version before it can access Swift classes.
如果您将 Objective-C 类替换为同名的 Swift 类,则需要打开 Storyboard,编辑自定义类的名称(如删除最后一个字母),保存 Storyboard,然后重命名该类背部.这将强制 Storyboard 文件升级到更新的版本,并且新的 Xcode 正确地编写自定义类键,如下所示:
If you replaced an Objective-C class with a Swift class with the same name, you need to open the Storyboard, edit the name of the custom class (like remove the last letter), save the Storyboard and then rename the class back. This will force the Storyboard file to be upgraded to a newer version, and the new Xcode to correctly write the custom class key like this:
版本信息差异:
UIButton 自定义类定义差异:
UIButton custom class definition diff:
在 Storyboard 文件中进行这些更改后,警告似乎消失了,并且使用了正确的自定义类.
After these changes in the Storyboard file the warning seems to disappear and the correct custom class is used.
这篇关于如何从同一个故事板访问 Objective-C 和 Swift 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从同一个故事板访问 Objective-C 和 Swift 类?


- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- UITextView 内容插图 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- URL编码Swift iOS 2022-01-01