Ios 从情节提要继承ViewController

Ios 从情节提要继承ViewController,ios,swift,inheritance,uiviewcontroller,Ios,Swift,Inheritance,Uiviewcontroller,我有一个名为CustomComponents.Storyboard的故事板,我在故事板中设计了BaseViewController。例如,我在Interface Builder中将BaseViewController的backgroundColor设置为.green。我从BaseViewController继承RootViewController。我希望RootViewController的backgroundColor为.green 这是我的RootViewController class R

我有一个名为
CustomComponents.Storyboard
的故事板,我在故事板中设计了
BaseViewController
。例如,我在Interface Builder中将
BaseViewController
backgroundColor
设置为
.green
。我从
BaseViewController
继承
RootViewController
。我希望
RootViewController
backgroundColor
.green

这是我的
RootViewController

class RootViewController: BaseViewController {

}
class BaseViewController: UIViewController {

}
这是我的
BaseViewController

class RootViewController: BaseViewController {

}
class BaseViewController: UIViewController {

}
这两个类都是空的,我刚刚在IB中设置了
backgroundColor

但是,当我运行应用程序时,我看到白色背景。但是,当在
BaseViewController
中以编程方式设置颜色时,绿色背景色将按预期应用于
RootViewController


继承故事板中设计的
BaseViewController
缺少什么?基本上,我想在情节提要中设计我的
BaseViewController
。我做错了什么?

只有在应用程序的最小规范是iOS 13的情况下,才能通过编程实现这一点,因为新的API可用于此目的,因为故事板不包含类声明,它是编码实例的存档

因此,如果您的
BaseViewController
具有标识符,则可以将编码的父对象实例化为
RootViewController

let rootController = UIStoryboard(name: "CustomComponents", 
    bundle: nil).instantiateViewController(identifier: 
                             "your_base_controller_identifier_here") { coder in
        RootViewController(coder: coder)
}
或者如果您的控制器是root

let rootController = UIStoryboard(name: "CustomComponents", 
     bundle: nil).instantiateInitialViewController { coder in
        RootViewController(coder: coder)
}

如何获取BaseViewController的引用??两者都是空类。我只是从
BaseViewController
继承,您需要从故事板实例化ViewController,否则无法从中查看更改。将Stroryboard想象为BaseViewController的实例,而不是类的定义。请检查以下内容:&&