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 类?
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01