简体   繁体   English

如何检测iPhone中是否单击了任何按钮

[英]How to detect wether any button is clicked or not in iphone

I have an iphone app i want that befor moving to next screen it should click on any of the 4 or five button i have and if user does not click on any button then it may not move to next screen 我有一个iPhone应用程序,我希望在移至下一个屏幕之前,它应单击我拥有的4个或5个按钮中的任何一个,如果用户未单击任何按钮,则它可能不会移至下一个屏幕

Firs two button from which user must click any one to move to next otherwise not 单击两个按钮,用户必须从中单击任意一个按钮以移至下一个按钮,否则

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

Next Button Move to the next Screen 下一个按钮移至下一个屏幕

-(IBAction)nextButton{

    FoodViewController*targetController=[[FoodViewController alloc]init];
    targetController.resturantLocation=resturantLocation;

    [self.navigationController pushViewController:targetController animated:YES];
}

Most Simple Way is to get a Flag.. in .h file Use a 最简单的方法是在.h文件中获取Flag ..

BOOL _flag;

in viewWillAppear set it as _flag = NO; viewWillAppear中将其设置为_flag = NO;

On your each button's action which are mendatory to click before going on next screen set it YES like: 在下一个屏幕上必须单击的每个按钮的操作上,将其设置为YES例如:

-(IBAction)locationOneButtonAction{
    // your stuff
    _flag = YES;
}
-(IBAction)locationTwoButtonAction{
    // your stuff
    _flag = YES;
}

In your next Button click use it like 在您的下一个按钮中单击使用,就像

-(IBAction)nextButton{

    if(_flag) {
        FoodViewController*targetController=[[FoodViewController alloc]init];
        targetController.resturantLocation=resturantLocation;
        [self.navigationController pushViewController:targetController animated:YES];
    }
}

Hope this helps :) Let me know if you are looking for something else 希望这会有所帮助:)让我知道您是否正在寻找其他东西

您可以使用bool标志来确定是否单击了任何按钮,如果单击了任何按钮,则只需将该bool标志设置为true,否则将其初始化为false,然后在用户单击next时只需检查该bool标志是否为true或false。如果为false,则不允许用户继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM