繁体   English   中英

在uibutton中绑定动作-反应性可可

[英]Bind action in uibutton -Reactive Cocoa

我宣布一项行动为

var postAction: Action<String, Data, NSError>!

现在我想要的是在按钮触发时触发此操作。

 triggerBtn.reactive.pressed = CocoaAction(postAction)

但是不能。使用可可粉按下按钮时如何触发某些动作?

我想出了一种观察动作的方法。

self.testBtn.reactive.trigger(for: .touchUpInside).observe{ event in
        //do something
        print(event)

    }

但是无法弄清楚如何获取发件人并绑定“自定义操作”吗?

您的操作的输入类型为String ,但默认的CocoaAction为无输入(类型() )。

根据按下按钮时输入的来源,可以使用一个固定值(如果此时知道该值):

button.reactive.pressed = CocoaAction(postAction, input: "Some Input")

或inputTransformer

button.reactive.pressed = CocoaAction(postAction) { sender in
    // Calculate input for the action when the button is pressed
    return "Some Value"
}

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM