简体   繁体   English

为什么Interface Builder在身份检查器中不显示视图控制器子类?

[英]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 试着

  • Removing references to files and adding them again 删除对文件的引用并再次添加它们
  • Editing the storyboard using a text editor and adding name to attribute "customClass" 使用文本编辑器编辑情节提要,并将名称添加到属性“ customClass”

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.

相关问题 使用Interface Builder连接到父视图控制器的IBAction的UIButton的子类? - Subclass of UIButton connecting to IBAction of parent View Controller using Interface Builder? 为什么在Interface Builder中向UITableViewCell子类添加手势识别器会使应用程序崩溃? - Why does adding a gesture recognizer to UITableViewCell subclass in Interface Builder crash the app? ios noob:为什么我的视图控制器不显示我在检查器中分配的标题 - ios noob: why doesn't my view controller show the title that I have assigned in the inspector UITextView的接口构建器和子类 - Interface builder and subclass of UITextView Interface Builder IB - 导航控制器,跳过视图 - Interface Builder IB - Navigation Controller, skipping a view 从视图控制器访问接口构建器对象 - Accessing interface builder object from view controller 使用Interface Builder时查看控制器遏制 - View Controller Containment when using Interface Builder 子类化UIView以在当前视图控制器上显示框 - Subclass UIView to show boxes on the current view controller 为什么我的IBDesignable UIButton子类未在Interface Builder中呈现? - Why Is My IBDesignable UIButton Subclass Not Rendering In Interface Builder? Xcode 6界面构建器不显示自定义类 - Xcode 6 interface builder does not show custom class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM