如何指定嵌套的自定义视图类? [英] How to specify nested custom view class?
问题描述
可用
嵌套类SuperView和NestedView。
Available nested classes SuperView and NestedView.
class SuperView : UIImageView {
class NestedView : UIImageView {
var text : String = "Nested View"
}
var text : String = "Super View"
var nested : NestedView?
}
我想要来设置对于UIImageView,名为Custom Class Name的属性在Storyboard场景的检查器中为NestedView值。但是Interface Builder找不到NestedView类。
I would like to set for a UIImageView the property named "Custom Class Name" to value "NestedView" inside the inspector of the storyboard scene. But the Interface Builder couldn't find "NestedView" class.
推荐答案
目前,我认为Interface Builder只识别Objective-C的名称类。您仍然可以使Interface Builder找到一个带有@objc关键字的嵌套类:
At this time, I think that Interface Builder only recognizes the names of Objective-C classes. You can still make Interface Builder find a nested class with the @objc keyword:
class SuperView: UIView {
@objc(SVNestedView) class NestedView: UIImageView {
}
}
然后,在Interface Builder中,指定该视图是SVNestedView类。由于Objective-C没有命名空间,你仍然需要为每个嵌套类选择唯一的名称,但至少Swift方面是正确的命名空间。
Then, in Interface Builder, specify that th view is of class SVNestedView. Since Objective-C isn't namespaced, you still need to pick unique names for each nested class, but at least the Swift side is properly namespaced.
这篇关于如何指定嵌套的自定义视图类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!