iPhone identify button pressed

女生的网名这么多〃 提交于 2019-12-23 02:56:09

问题


I have a view with several buttons that all have the same target and action.

At the moment the action is @selector(doSomething).

I need to be able to determine which button is pressed but I'm not sure of the best way to do this.

The method doSomething is declared as...

-(void)doSomething;

Is there a better way to declare this so I can get more info out?

Thanks for any help!

Oliver


回答1:


If you declare the method as

- (void)doSomething:(UIButton *)sender

with the corresponding selector @selector(doSomething:), then you can check the identity of the sender using either of the methods Joshua suggested.




回答2:


Target/action messages provide the sender as the argument. In your case, the button that called the message is the sender. You could ask it for its -tag (which you can set in IB) or you could name it as an outlet and test for equality: if (sender == myButtonOne) ...



来源:https://stackoverflow.com/questions/3552300/iphone-identify-button-pressed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!