【发布时间】:2019-06-19 09:42:13
【问题描述】:
背景:
我正在设置一个 BaseViewController,它在 Swift 中继承 UIViewController,以便所有其他 ViewController 类继承并采用它的属性。
问题:
但是,当创建一个也继承自 UIPageViewController(和 BaseViewController)的类时,我们有 UIViewController 的继承重叠。
这会导致多重继承错误。还有什么其他的建模方法?
试过了:
我已尝试使用协议方法,以便 BasePageViewController 将实现协议 BaseViewController,但是,我找不到将函数放入协议以供 BasePageViewController 继承的方法。另外,我不知道这可能对未来产生什么影响。
任何帮助将不胜感激,谢谢!
class BaseViewController: UIViewController {
func someFunction(){}
}
class PageBaseViewController: BaseViewController, UIPageViewController {
//this class overlaps in inheritance to UIViewController
// Error -> Multiple Inheritance from classes UIPageViewController and BaseViewController
}
【问题讨论】:
-
您可以扩展
protocol并将您的逻辑放入函数中。