Reputation: 1059
I have 1 button and 2 methods. One method calls this:
[button addTarget:self action:@selector(action1) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
And the other calls this:
[button addTarget:self action:@selector(action2) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
For some reason, the button's action will not change. I am sure I am calling the above code correctly. Is it trying to add an action to the button and making it call both functions? If so, how can I stop this from happening? I have tried releasing and setting the button to nil before setting the new action and no luck. Thanks for the help.
Upvotes: 1
Views: 181
Reputation: 181270
Yes. It's actually calling action1
and action2
. You need to call removeTarget
before adding the new target on the button.
Upvotes: 2