ラジオボタンで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];
}