【问题标题】:Create ControlProperty for custom UIControl为自定义 UIControl 创建 ControlProperty
【发布时间】:2017-05-11 14:09:45
【问题描述】:

是否可以扩展 Reactive 结构,其中基类是我从 UIControl 继承的自定义控件?

当我尝试以下代码时:

extension Reactive where Base: CustomControl {

    public var value: ControlProperty<CGFloat> {

        return CustomControl.rx.value(

            self.base,

            getter: { customControl in
                customControl.customProperty
            },
            setter: { customControl, value in
                customControl.customProperty = value
            }
        )
    }
}

我收到以下错误:

Instance member "value" cannot be used on type 'Reactive<CustomControl>'

如果您能给我任何解释,我将不胜感激。

【问题讨论】:

    标签: swift uicontrol rx-swift reactive rx-cocoa


    【解决方案1】:

    您可以查看此链接:https://github.com/ReactiveX/RxSwift/issues/991

    value 方法不是公开的,因此您需要创建它的公开版本。之后,就可以为您的自定义控件创建扩展了。

    【讨论】:

      猜你喜欢
      • 2020-09-07
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多