I have a UIButton which is created programmatically. How do I get this UIButton to send its touch up events to an IBAction I have?
addTarget:action:forControlEvents:
method.
[myButton addTarget:myClass action:@selector(myEventHandler) forControlEvents: UIControlEventTouchUpInside];
From http://developer.apple.com/library/ios/#documentation/uikit/reference/UIControl_Class/Reference/Reference.html.
with this line of code you will fire UIbutton action by programmatically
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
For swift
button.addTarget(self, action:#selector(functionNameHere), for: UIControl.Event.touchUpInside)
[button addTarget:self
action:@selector(myMethod:)
forControlEvents:UIControlEventTouchUpInside];
Like magic =)
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