简体   繁体   中英

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 () ).

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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