I need to send extra arguments to a method on button press, but can't find a way to make addTarget send a selector to do that.
I'd rather use a block anyway, but is there a method for attaching a block to a UIButton at run time?
Yes, you can do it easily with BlocksKit library:
#import <BlocksKit/UIControl+BlocksKit.h>
[someButton addEventHandler:^(id sender) {
// some action here
} forControlEvents:(UIControlEventTouchUpInside)];
or use RxSwift button.rx.tap observable.
Not by default. You could subclass UIButton to make this happen, though. Someone did it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With