[英]how to check that any of the button is clicked or not in iphone application
我有六个按钮,我希望用户必须先选择六个按钮中的任意一个,然后再移至下一个屏幕(如果未选择),则不应移至下一个屏幕。如果单击六个按钮中的任何一个,则用户可以移至下一个屏幕
-(IBAction)locationOneButtonAction{
// your stuff
_flag = YES;
}
-(IBAction)locationTwoButtonAction{
// your stuff
_flag = YES;
}
我认为这个问题的最佳解决方案是为您的类声明一个布尔值(假设它被称为“ ClickViewController”,例如(所以在顶部)
@interface ClickViewController () {
bool wasClicked;
}
...
-(IBAction)locationOneButtonAction{
// your stuff
wasClicked = YES;
}
然后,当单击应移至下一页的按钮时,请使用类似的方法。
-(void)nextPageClicked{
if (wasClicked){
[self performSegueWithIdentifier:@"segueIdentifier" sender: self];
} else {
// do something else here, like tell the user why you didn't move them
}
}
这意味着您无法将按钮从按钮绘制到下一个视图。 如果使用情节提要板,则意味着您无法从应该将其移动到下一个视图的按钮上绘制序列,而应该从视图控制器图标将其绘制到下一个视图。 然后选择segue,为其命名,并使用上面的方法命名。
我也不确定您是否要让每个按钮移至下一个视图,如果是这样,则可以使用基本相同的代码,而只需将代码[self performSegueWithIdentifier:@“ segueIdentifier”发件人:自我]; 该按钮的实际作用。
希望这会有所帮助。
最初添加BOOL _flag; int curIndex; 在.h文件中。
现在添加_flag = FALSE; 在viewDidLoad方法中,因为它指示未单击任何按钮。
使每个按钮的userInteractionEnabled能够单击并将标记添加到每个按钮。
现在,在每次单击按钮的操作方法中执行以下操作:
(IBAction)locationOneButtonAction:(id)sender{
curIndex = [sender tag]; //which button clicked
// your stuff
_flag = TRUE;
}
-(IBAction)locationTwoButtonAction{
curIndex = [sender tag]; //which button clicked
// your stuff
_flag = YES;
}
........
........
现在检查是否单击了按钮,如下所示:
if(_flag)
{
NSLog(@"Button clicked with tag: %d",curIndex);
}
else
{
NSLog(@"Not any Button clicked");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.