如何检测iphone中是否点击了任何按钮
我有一个iphone应用程序,我想在移动到下一个屏幕之前,它应该点击我的4个或5个按钮中的任何一个,如果用户没有点击任何按钮,那么它可能不会移动到下一个屏幕 前两个按钮,用户必须单击其中任何一个按钮才能移动到下一个按钮,否则不会如何检测iphone中是否点击了任何按钮,iphone,ios,xcode,Iphone,Ios,Xcode,我有一个iphone应用程序,我想在移动到下一个屏幕之前,它应该点击我的4个或5个按钮中的任何一个,如果用户没有点击任何按钮,那么它可能不会移动到下一个屏幕 前两个按钮,用户必须单击其中任何一个按钮才能移动到下一个按钮,否则不会 -(IBAction)locationOneButtonAction{ UIImage *buttonImage = [UIImage imageNamed:@"radiogreen.png"]; UIImage *buttonImageOne=[
-(IBAction)locationOneButtonAction{
UIImage *buttonImage = [UIImage imageNamed:@"radiogreen.png"];
UIImage *buttonImageOne=[UIImage imageNamed:@"radiowhite.png"];
[locationOneButton setImage:buttonImage forState:UIControlStateNormal];
[locationOneButton setImage:buttonImage forState:UIControlStateNormal];
[locationThreeButton setImage:buttonImageOne forState:UIControlStateNormal];
[locationTwoButton setImage:buttonImageOne forState:UIControlStateNormal];
[locationFourButton setImage:buttonImageOne forState:UIControlStateNormal];
[locationFiveButton setImage:buttonImageOne forState:UIControlStateNormal];
[locationSixButton setImage:buttonImageOne forState:UIControlStateNormal];
resturantLocation=@"Common Man - Bedford, MA";
}
-(IBAction)locationTwoButtonAction{
UIImage *buttonImage = [UIImage imageNamed:@"radiogreen.png"];
UIImage *buttonImageOne=[UIImage imageNamed:@"radiowhite.png"];
[locationOneButton setImage:buttonImageOne forState:UIControlStateNormal];
[locationThreeButton setImage:buttonImageOne forState:UIControlStateNormal];
[locationTwoButton setImage:buttonImage forState:UIControlStateNormal];
[locationFourButton setImage:buttonImageOne forState:UIControlStateNormal];
[locationFiveButton setImage:buttonImageOne forState:UIControlStateNormal];
[locationSixButton setImage:buttonImageOne forState:UIControlStateNormal];
resturantLocation=@"Common Man - Arlingtion, NY";
}
下一步按钮移动到下一屏幕
-(IBAction)nextButton{
FoodViewController*targetController=[[FoodViewController alloc]init];
targetController.resturantLocation=resturantLocation;
[self.navigationController pushViewController:targetController animated:YES];
}
您可以使用bool标志来标识是否单击了任何按钮。如果单击了任何按钮,只需将bool标志设置为true,否则将其初始化为false,当用户单击“下一步”时,只需检查bool标志是否为true或false。如果为false,则不允许用户继续操作。最简单的方法是获取标志。。 在.h文件中使用
BOOL _flag;
在视图中将出现将其设置为\u flag=NO代码>
在进入下一屏幕之前,单击每个按钮的操作,将其设置为YES
如下:
-(IBAction)locationOneButtonAction{
// your stuff
_flag = YES;
}
-(IBAction)locationTwoButtonAction{
// your stuff
_flag = YES;
}
在“下一步”按钮中,单击“像这样使用”
-(IBAction)nextButton{
if(_flag) {
FoodViewController*targetController=[[FoodViewController alloc]init];
targetController.resturantLocation=resturantLocation;
[self.navigationController pushViewController:targetController animated:YES];
}
}
希望这有帮助:)如果您正在寻找其他内容,请告诉我我的意思是,我有两个按钮,其中一个按钮应该被单击是的,我找到了。但是如果两个按钮都被点击了,请告诉我你想要什么?如果你同时点击两个或任何一个按钮,我的解决方案就会起作用。