【发布时间】:2020-03-09 11:33:28
【问题描述】:
我有一个名为 CustomComponents.storyboard 的 Storyboard,我在 Storyboard 中设计了 BaseViewController。例如,我在 Interface Builder 中将 BaseViewController 的 backgroundColor 设置为 .green。我从BaseViewController 继承RootViewController。我希望RootViewController 的backgroundColor 是.green。
这是我的RootViewController
class RootViewController: BaseViewController {
}
这是我的BaseViewController
class BaseViewController: UIViewController {
}
两个类都是空的,我刚刚在 IB 中设置了backgroundColor。
但是,当我运行应用程序时,我看到了白色背景。但是,当在BaseViewController 中以编程方式设置颜色时,绿色背景颜色将按预期应用到RootViewController。
继承在 Storyboard 中设计的 BaseViewController 我缺少什么?基本上,我想在 Storyboard 中设计我的BaseViewController。我做错了什么?
【问题讨论】:
-
BaseViewController的引用是怎么得到的??
-
两者都是空类。我只是继承自
BaseViewController -
您需要从情节提要中实例化 ViewController,否则无法从中查看更改。将 Stroryboard 想象为 BaseViewController 的实例,而不是类的定义
标签: ios swift inheritance uiviewcontroller