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 类?
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01