开发者

iPhone SDK: Programmatically change IBAction

开发者 https://www.devze.com 2022-12-20 01:43 出处:网络
Is there a way I can programmatically change the IBAction of a UI开发者_如何学CButton? I know I can just create two buttons and use button.hidden = BOOL, but I\'d much rather just change the IBAction

Is there a way I can programmatically change the IBAction of a UI开发者_如何学CButton?

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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消