在 uibutton 中绑定动作 -Reactive Cocoa
Bind action in uibutton -Reactive Cocoa
我已将操作声明为
var postAction: Action<String, Data, NSError>!
现在我想要的是在按钮触发时触发这个动作。
triggerBtn.reactive.pressed = CocoaAction(postAction)
但是,t.How 我可以在按下按钮时使用反应式 cocoa 触发一些动作吗?
我想出了观察动作的方法
self.testBtn.reactive.trigger(for: .touchUpInside).observe{ event in
//do something
print(event)
}
但不知道如何获取发件人并绑定自定义操作?
您的 Action 有 String
类型的输入,但默认的 CocoaAction 没有输入(()
类型)。
根据按下按钮时输入的来源,您可以使用固定值(如果此时已知):
button.reactive.pressed = CocoaAction(postAction, input: "Some Input")
或输入转换器
button.reactive.pressed = CocoaAction(postAction) { sender in
// Calculate input for the action when the button is pressed
return "Some Value"
}
我已将操作声明为
var postAction: Action<String, Data, NSError>!
现在我想要的是在按钮触发时触发这个动作。
triggerBtn.reactive.pressed = CocoaAction(postAction)
但是,t.How 我可以在按下按钮时使用反应式 cocoa 触发一些动作吗?
我想出了观察动作的方法
self.testBtn.reactive.trigger(for: .touchUpInside).observe{ event in
//do something
print(event)
}
但不知道如何获取发件人并绑定自定义操作?
您的 Action 有 String
类型的输入,但默认的 CocoaAction 没有输入(()
类型)。
根据按下按钮时输入的来源,您可以使用固定值(如果此时已知):
button.reactive.pressed = CocoaAction(postAction, input: "Some Input")
或输入转换器
button.reactive.pressed = CocoaAction(postAction) { sender in
// Calculate input for the action when the button is pressed
return "Some Value"
}