[英]Why does Interface Builder not show a view controller subclass in the identity inspector?
I have a BaseViewController
and I want to inherit from this in a subclass. 我有一个
BaseViewController
,我想在子类中从中继承。 When I do this the subclass "TestViewController" doesn't appear under the class dropdown in Xcode's interface builder (see below image). 当我这样做时,“ TestViewController”子类不会出现在Xcode的界面构建器的类下拉列表下(请参见下图)。 Isn't this possible?
这不可能吗?
class BaseViewController<T: AnyObject> : UIViewController{
var test: T?
override func viewDidLoad() { }
}
class TestViewController : BaseViewController<UIView>{ }
If I just type in the class name then I get a runtime error saying: 如果我只输入类名,则会收到运行时错误提示:
Unknown class TestViewController in Interface Builder file 接口生成器文件中的未知类TestViewController
Tried 试着
Pretty simple: You can't use a generic type here. 很简单:您不能在此处使用泛型类型。 The reason is that UIKit is written in ObjC, and generic types are not fully visible to ObjC.
原因是UIKit是用ObjC编写的,并且通用类型对ObjC并不完全可见。 This answer goes into the details.
这个答案进入细节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.