如何检测iphone中是否有任何按钮被点击

时间:2012-07-02 04:49:57

标签: iphone ios xcode

我有一个iphone应用程序,我想要移动到下一个屏幕它应该点击我有的任何4或5按钮,如果用户没有点击任何按钮,那么它可能不会移动到下一个屏幕

Firs两个按钮,用户必须从中单击任何一个按钮才能移动到下一个按钮,否则

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

2 个答案:

答案 0 :(得分:1)

最简单的方法是获得一个国旗.. 在.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];
    }
}

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

答案 1 :(得分:0)

您可以使用bool标志来识别是否单击了任何按钮。如果单击任何按钮,只需将该bool标志设为true,否则将其初始化为false,当用户单击next时,只需检查该bool标志是真还是假。如果是假,则不允许用户继续。