How would I be able to run an IBAction based on another event? For example I could use a piece of code to run an IBAction.
What I'm trying to do is have two different buttons run one or more IBActions.
How would I be able to run an IBAction based on another event? For example I could use a piece of code to run an IBAction.
What I'm trying to do is have two different buttons run one or more IBActions.
You can hook multiple buttons up to the same IBAction, so you could do it that way.
But IBActions are just methods. For example, if you have some action doSomething:
, you can just call it on an object:
[obj doSomething:nil];
An IBAction is just a hint for the Interface Builder. It's actually another way of saying void.
#define IBAction void
So there is nothing special about it. In Interface Builder, you can connect touch event for different buttons to the same IBAction. You can also call IBAction methods from another IBAction method. Use the sender argument to identify the source of the event.
For example,
-(IBAction)buttonTapped:(id)sender {
UIButton *btn = (UIButton *)sender;
NSLog(@"tapped: %@", btn.titleLabel.text);
[self anotherIBAction:sender];
}