简体   繁体   English

在TabBarController中覆盖ViewControllers的类型?

[英]Override type for ViewControllers in TabBarController?

I'm trying to override type for viewControllers manner. 我试图覆盖viewControllers方式的类型。

override var viewControllers : [BaseViewController]? {
    get {
        return self.viewControllers
    }
}

But I get this error. 但是我得到了这个错误。

Property 'viewControllers' with type '[BaseViewController]?' cannot override a property with type '[UIViewController]?'

Can this even be done? 甚至可以这样做吗?

You can workaround it by creating new property. 您可以通过创建新属性来解决此问题。 Like this for instance. 比如这样。

var baseViewControllers: [BaseViewController]? {
      return self.viewControllers as? [BaseViewController] 
}

You cannot override properties type which is already of type UIViewController. 您不能覆盖已经是UIViewController类型的属性类型。 What you can do is to cast the property viewControllers to [BaseViewController]?. 你可以做的是将属性viewControllers转换为[BaseViewController]?。

class base: UIViewController {

}

class tab: UITabBarController {
  override func viewDidLoad() {
    super.viewDidLoad()
    let bases = viewControllers as? [base]
  }
  override var viewControllers: [UIViewController]? {
    get {
        return [base()]
    }
    set {

    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在TabbarController中设置viewControllers的委托? - How to set delegate of viewControllers in TabbarController? 一个tabBarController中的一个选项卡的两个ViewController - two ViewControllers for one tab in a tabBarController 如何有条件地设置tabbarcontroller viewControllers? - How to set tabbarcontroller viewControllers conditionally? libc ++ abi.dylib:以NSException类型的未捕获异常终止(lldb)TabBarController-> TableViews-> ViewControllers - libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) TabBarController->TableViews->ViewControllers self.tabBarController!.viewControllers返回nil - self.tabBarController!.viewControllers returning nil TabBarController上NavigationBar中的AddButton并从ViewControllers调用Segue - AddButton in NavigationBar on TabBarController and call Segue from ViewControllers 如何将 rightBarButtonItem 传递给 TabBarController 中的所有 ViewController? - How to pass rightBarButtonItem to all ViewControllers in TabBarController? NavigationController中的TabBarController在viewControllers中不显示TabBar - TabBarController in NavigationController does not show TabBar in viewControllers 将ViewController添加到TabbarController后失去交互性 - Viewcontrollers loses interactivity after adding it to tabbarcontroller 如何在从SlideMenuViewController实例化的ViewControllers中打开TabBarController - How to open a TabBarController in ViewControllers that Instantiate from SlideMenuViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM