[英]Bind action in uibutton -Reactive Cocoa
I have declared a action as 我宣布一项行动为
var postAction: Action<String, Data, NSError>!
now what i want is to trigger this action when the button triggers. 现在我想要的是在按钮触发时触发此操作。
triggerBtn.reactive.pressed = CocoaAction(postAction)
But can't.How can i trigger some action when a button is pressed using reactive cocoa? 但是不能。使用可可粉按下按钮时如何触发某些动作?
I have figured out a way to observe the actions. 我想出了一种观察动作的方法。
self.testBtn.reactive.trigger(for: .touchUpInside).observe{ event in
//do something
print(event)
}
But cant figure out how to get the sender and bind Custom Action? 但是无法弄清楚如何获取发件人并绑定“自定义操作”吗?
Your Action has an input of type String
, but the default CocoaAction is no input (type ()
). 您的操作的输入类型为String
,但默认的CocoaAction为无输入(类型()
)。
Depending on where your input should come from when the button is pressed, you can use either a fixed value (if its known at this point): 根据按下按钮时输入的来源,可以使用一个固定值(如果此时知道该值):
button.reactive.pressed = CocoaAction(postAction, input: "Some Input")
or an inputTransformer 或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.