0

这是我的后退按钮代码。
我有 9 个按钮(button1,button2...button9)
,如果我按下其他 9 个按钮中的任何一个,我希望这个按钮激活。
那么有没有办法我可以做到这一点?

[_backButtonOutlet addTarget:self action:@selector(button1:) forControlEvents:UIControlEventTouchUpInside];
4

3 回答 3

0

创建一些方法将同时调用您想要调用的所有所需方法,并在按钮点击事件上调用该方法。祝你好运!

于 2013-10-12T11:41:36.717 回答
0

_backButtonOutlet是对按钮的引用,因此您不希望在按下任何按钮时调用它。button1:是按下任何按钮时要调用的方法。

选项1:

称呼:

[otherButtonOutlet_N addTarget:self action:@selector(button1:) forControlEvents:UIControlEventTouchUpInside];

在其他每个按钮上(otherButtonOutlet_N根据需要更换)。

选项 2:

在您的 XIB / 故事板中,将所有按钮连接到该button1:方法。您可以将多个目标/操作对添加到一个按钮。

于 2013-10-12T12:17:07.770 回答
0
-(IBAction) button1:(id)sender
{
      [self btn1Pressed:sender];
      [self btn2Pressed:sender];
      [self btn3Pressed:sender];
      [self btn4Pressed:sender];
      [self btn5Pressed:sender];
      [self btn6Pressed:sender];
      [self btn7Pressed:sender];
      [self btn8Pressed:sender];
}
于 2013-10-12T12:13:57.100 回答