Question

Is there a way I can programmatically change the IBAction of a UIButton?

I know I can just create two buttons and use button.hidden = BOOL, but I'd much rather just change the IBAction itself.

Was it helpful?

Solution

Sure. You can use addTarget:forControlEvents: and removeTarget:action:forControlEvents: to manage the connections between action methods and controls manually. Both methods are in UIControl.

OTHER TIPS

I'm not sure I understand the question? Why not have the IBAction call a custom method and put some logic about which action to take in that method?

Sure:

-removeTarget:action:forControlEvents: to remove the old action

-addTarget:action:forControlEvents: to add the new action

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top