我有四个 UI 按钮,我希望根据用户按下的按钮发生不同的事情。我尝试使用 bool 值来检查按钮是否被按下,但它似乎不起作用。每个按钮的 bool 代码基本上是:
-(IBAction)FirstChoice:(id)sender
{
wasClicked = YES;
}
然后在主函数本身中:
if(wasClicked)
{
returnView.text = @"Test";
}
但是,当我按任何按钮时,测试文本不会出现。
最佳答案
我认为你应该为所有按钮使用一个通用的“Touch up inside” socket 功能......并为每个按钮设置不同的标签......例如
-(IBAction)FirstChoice:(id)sender // common "Touch up inside" action for all four buttons
{
UIButton *btn=(UIButton *)sender; //assuming that you have set tag for buttons
if(btn.tag==94)
{
//Do any thing for button 1
}
else if (btn.tag==93)
{
returnView.text = @"Test";
//Do any thing for button 2
}
else if (btn.tag==92)
{
//Do any thing for button 3
}
else
{
//Do any thing for button 4
}
}
关于ios - 检查 UIButton 是否被按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20296605/