开发者

iPhone SDK: Programmatically change 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜