1

ラジオボタンで3つの質問があります。ユーザーが次の画面に移動しないようにすべての質問に答えてほしいので、BOOL isClickedを宣言し、すべてのボタンがクリックされたときにtrueにします。

しかし、ボタンのいずれかが選択されて次の画面に移動すると機能しますが、3つの質問ボタンすべてをチェックする必要があるため、すべてのボタンまたは他の何かに異なるブール値を追加する必要があります。

     -(IBAction)button1Action{


UIImage *img = [UIImage imageNamed:@"selected.png"];
UIImage *img1=[UIImage imageNamed:@"unselected.png"];
[button1 setImage:img forState:UIControlStateNormal];
[button2 setImage:img1 forState:UIControlStateNormal];
[button3 setImage:img1 forState:UIControlStateNormal];
    option1=@"Less than 2 hours";

isClicked = YES;
}
   -(IBAction)button2Action{


UIImage *img = [UIImage imageNamed:@"selected.png"];
UIImage *img1=[UIImage imageNamed:@"unselected.png"];
[button1 setImage:img1 forState:UIControlStateNormal];
[button2 setImage:img forState:UIControlStateNormal];
[button3 setImage:img1 forState:UIControlStateNormal];



option2=@"2-5 hours";

isClicked = YES;

}


   -(IBAction)button3Action{

UIImage *img = [UIImage imageNamed:@"selected.png"];
UIImage *img1=[UIImage imageNamed:@"unselected.png"];
[button1 setImage:img1 forState:UIControlStateNormal];
[button2 setImage:img1 forState:UIControlStateNormal];
[button3 setImage:img forState:UIControlStateNormal];
option3=@"More than 5 hours";

isClicked = YES;

}



   if (isClicked) {


    [self save_Local];


    SecondViewController*targetController=[[SecondViewController alloc]init];

    targetController.responseOne=responseOne;
    targetController.responseTwo=responseTwo;
    targetController.responseThree=responseThree;
    targetController.responseFour=responseFour;
    targetController.teritory=teritory;


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



}

else {





    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please provide all responses before proceeding to the next screen" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];



}
4

2 に答える 2

2

このシナリオでは、3 つの異なるブール値を追加するか、代わりにカウンターを追加してこれを確認できます。回答が得られたらカウンターを増やします。次に、現在の if ステートメントをif(noOfclicks > MIN_ANSWERS_REQUIRED)noOfClicks がカウンターになり、場合によって MIN_ANSWERS_REQUIRED が 3 になる場所で置き換えることができます。

または

あなたが言ったように、これらは答えなので、変数に値を割り当てる必要があります。この変数に、回答にないデフォルト値を割り当てることができます。次に、ユーザーが次の画面に移動するためにクリックすると、すべての回答の値がデフォルト値と異なるかどうかを確認します。

于 2013-01-31T05:48:13.460 に答える
1

.hファイルでintカウントを宣言します。Viewdidloadでmakecount= 0;

-(IBAction)button1Action{
UIImage *img = [UIImage imageNamed:@"selected.png"];
UIImage *img1=[UIImage imageNamed:@"unselected.png"];
[button1 setImage:img forState:UIControlStateNormal];
[button2 setImage:img1 forState:UIControlStateNormal];
[button3 setImage:img1 forState:UIControlStateNormal];
option1=@"Less than 2 hours";
count=count+1;
}
-(IBAction)button2Action
{
UIImage *img = [UIImage imageNamed:@"selected.png"];
UIImage *img1=[UIImage imageNamed:@"unselected.png"];
[button1 setImage:img1 forState:UIControlStateNormal];
[button2 setImage:img forState:UIControlStateNormal];
[button3 setImage:img1 forState:UIControlStateNormal];
option2=@"2-5 hours";
count=count+1;
}
-(IBAction)button3Action{ 
UIImage *img = [UIImage imageNamed:@"selected.png"];
UIImage *img1=[UIImage imageNamed:@"unselected.png"];
[button1 setImage:img1 forState:UIControlStateNormal];
[button2 setImage:img1 forState:UIControlStateNormal];
[button3 setImage:img forState:UIControlStateNormal];
option3=@"More than 5 hours";
count=count+1;
}
-(IBAction)Push
{
if (count==3) {
    [self save_Local];
    SecondViewController*targetController=[[SecondViewController alloc]init];
    targetController.responseOne=responseOne;
    targetController.responseTwo=responseTwo;
    targetController.responseThree=responseThree;
    targetController.responseFour=responseFour;
    targetController.teritory=teritory;
    [self.navigationController pushViewController:targetController animated:YES];
}
else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please provide all responses before proceeding to the next screen" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
}
}

多分それはあなたを助けるでしょう。ハッピーコーディング

于 2013-01-31T06:29:04.473 に答える