So far, I've been using
[button1 addTarget:self action:@selector(newAction) forControlEvents:UIControlEventTouchUpInside];
which adds an additional action (I think). How can I replace the initial action with a new one?
You can remove a target for a specific action like this:
[button1 removeTarget: self action: @selector(oldAction) forControlEvents: UIControlEventTouchUpInside]
Or, better yet, you can remove all targets from your button like this:
[button1 removeTarget: nil action: NULL forControlEvents: UIControlEventAllEvents]
Then, you can add your new target action:
[button1 addTarget:self action:@selector(newAction) forControlEvents: UIControlEventTouchUpInside];
That's pretty much it!
You first have to remove the current action with removeTarget:action:forControlEvents: and then add the new one with addTarget:action:forControlEvents:.
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