[英]How to bind Signal<Bool, NoError> to enabled property of UIButton in Reactive Cocoa 4
[英]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.