gpt4 book ai didi

ios - 在 Swift 中,使用选择器 init 覆盖的方法具有不兼容的类型

转载 作者:行者123 更新时间:2023-11-30 14:10:35 28 4
gpt4 key购买 nike

我是 Swift 新手,我正在尝试像下面这样子类化:

public class CombinedChartRenderer: ChartDataRendererBase {

private weak var _chart: CombinedChartView!

public init(chart: CombinedChartView, animator: ChartAnimator, viewPortHandler: ChartViewPortHandler)
{
super.init(animator: animator, viewPortHandler: viewPortHandler)

_chart = chart

createRenderers()
}
}

public class MyCombinedChartRenderer: CombinedChartRenderer {
private weak var _chart: MyCombinedChartView!
public override init(chart: MyCombinedChartView, animator: ChartAnimator, viewPortHandler: ChartViewPortHandler)
{
super.init(chart: chart, animator: animator, viewPortHandler: viewPortHandler)

_chart = chart
}
}

它总是说

使用选择器“initWithChart:animator:viewPortHandler:”的重写方法具有不兼容的类型“(MyCombinedChartView、ChartAnimator、ChartViewPortHandler) -> MyCombinedChartRenderer”

我不确定它出了什么问题。我看到其他代码可以通过提供更专门的子类来执行此类初始化。

CombinedChartView 就像:

public class CombinedChartView: BarLineChartViewBase
{
...
}

public class MyCombinedChartView: CombinedChartView
{
// do some customization and override
}

最佳答案

只需更改一些变量名称,与 init 发生冲突并删除该覆盖关键字即可;

public class CombinedChartRenderer: ChartDataRendererBase {

private weak var _chart: CombinedChartView!

public init(chart: CombinedChartView, animator: ChartAnimator, viewPortHandler: ChartViewPortHandler)
{
super.init(animator: animator, viewPortHandler: viewPortHandler)

_chart = chart

createRenderers()
}
}

public class MyCombinedChartRenderer: CombinedChartRenderer {
private weak var _myChart: MyCombinedChartView!
public init(myChart: MyCombinedChartView, animator: ChartAnimator, viewPortHandler: ChartViewPortHandler)
{
super.init(chart: myChart, animator: animator, viewPortHandler: viewPortHandler)

_myChart = myChart // This can be removed by marking baseclass instance '_chart' as public;
}
}

关于ios - 在 Swift 中,使用选择器 init 覆盖的方法具有不兼容的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31824422/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com