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?
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?
Hello pureman,
First, you'll need a reference to your button1. Then you need to unregister the target by calling following action:
[button1 removeTarget:self action:@selector(oldAction) forControlEvents:UIControlEventTouchUpInside]
You may pass nil as action, this will remove all actions from connected with that target from button.
Then, you need to call
[button1 addTarget:self action:@selector(newAction) forControlEvents: UIControlEventTouchUpInside];
That's pretty it!
Hope this was helpful, Pawel
You first have to remove the current action with removeTarget:action:forControlEvents: and then add the new one with addTarget:action:forControlEvents:.