In this SO question, user feihu
recommends an approach with a different action as the target for the TouchUpInside
event.
Here are the relevant pieces:
[btn addTarget:self action:@selector(btnTouchUp:withEvent:) forControlEvents:UIControlEventTouchUpInside];
(void)btnTouchUp:(UIButton *)sender withEvent:(UIEvent *)event {
...
}
Converting this code to Swift has been maddening.
We tried:
button.addTarget(self, action: "buttonTouchUp:", forControlEvents: .TouchUpInside)
func buttonTouchUp(sender: AnyObject, event: UIEvent) {
...
}
and
button.addTarget(self, action: "buttonTouchUp:", forControlEvents: .TouchUpInside)
func buttonTouchUp(sender: UIButton!, event: UIEvent) {
...
}
Anything other than the standard action message (with sender: UIButton!
as the only parameter) generates an exception saying an unrecognized selector was sent.
Searching Apple docs for other signatures on action messages yields nothing. We checked the UIButton
and UIControl
classes.
We Googled UIButton action message
, UIControl selector action
, UIButton events
, UIButton action function signature
, and all sorts of variations, but nothing.
How can we convert his Obj-C code? Or where can we find all the possible actions which can be used for handling UIButton
events?