gpt4 book ai didi

iphone - 如何检测iphone中的某个按钮是否被点击

转载 作者:行者123 更新时间:2023-11-29 04:34:02 25 4
gpt4 key购买 nike

我有一个 iPhone 应用程序,我希望在移动到下一个屏幕之前,它应该单击我拥有的 4 个或 5 个按钮中的任何一个,如果用户没有单击任何按钮,那么它可能不会移动到下一个屏幕

第一个按钮,用户必须单击其中任何一个按钮才能移至下一个,否则不能

-(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];
}

最佳答案

最简单的方法是获得一个标志..在 .h 文件中使用

BOOL _flag;

viewWillAppear中将其设置为_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];
}
}

希望这有帮助:)如果您正在寻找其他东西,请告诉我

关于iphone - 如何检测iphone中的某个按钮是否被点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11287910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com