HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何确定从三个按钮中按下了哪个按钮大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有三个按钮,他们都做同样的事情执行一个segue.所有都链接到相同的连接.

- (IBACtion)difficultyButtonPressed:(id)sender {
    // Any difficulty @R_197_10288@cted
    [self performSegueWithIdentifier:@"mainGameTurnGuess" sender:self];
}

我需要做的是确定prepareForSegue方法中按下了什么按钮.如何判断按下三个按钮中的哪一个.

不看按钮上的措辞/文字,因为这会改变本地化.

解决方法

你可以使用Tag Value来设置Taped Button,假设你有树按钮例如: –

@property (nonatomic,strong)  UIButton *btn1;
@property (nonatomic,strong) UIButton *btn2;
@property (nonatomic,strong) UIButton *btn3;

然后设置按钮标签,如: –

btn1.tag=1;
btn2.tag=2;
btn3.tag=3;

并为每个按钮设置相同的IBACtion,并: –

[btn1 addTarget:self action:@@R_197_10288@ctor(difficultyButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

[btn2 addTarget:self action:@@R_197_10288@ctor(difficultyButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

[btn3 addTarget:self action:@@R_197_10288@ctor(difficultyButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

- (IBACtion)difficultyButtonPressed:(UIButton*)sender
{
 NSLog(@"Button tag is %d",sender.tag);

     // you can use if else condition using sender.tag  like

      if(sender.tag==1)//first button related identifire
      {
           [self performSegueWithIdentifier:@"mainGameTurnGuess_FirstButtonIdentirier" sender:sender]; 
      }
      else if(sender.tag==2)//second button related identifier
      {
            [self performSegueWithIdentifier:@"mainGameTurnGuess_secondButtonIdentirier" sender:sender]; 
      }
      else   //Third button related identifier
      {
            [self performSegueWithIdentifier:@"mainGameTurnGuess_ThirdButtonIdentirier" sender:sender]; 
      }

}

对于信息

如果你在IBACtion中使用id,那么你得到的Button对象如下: –

- (IBACtion)difficultyButtonPressed:(id)sender {
    UIButton *button = (UIButton *)sender;
    NSLog(@"Button tag is %d",button.tag);
}

大佬总结

以上是大佬教程为你收集整理的ios – 如何确定从三个按钮中按下了哪个按钮全部内容,希望文章能够帮你解决ios – 如何确定从三个按钮中按下了哪个按钮所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。