我在应用程序中有按钮我希望当用户点击该按钮时它应该显示未选择的问题标签文本为红色
只有一个标签文字正在改变Q1,而不是其他文字。
-(IBAction)nextButtonClicked { if ([professionLabel.text isEqualToString:@"Profession"]) { errorLabel.text=@"Please Select the Highlighted Answers"; Q1.textColor=[UIColor redColor]; } else if ([workLabel.text isEqualToString:@"Work"]) { errorLabel.text=@"Please Select the Highlighted Answers"; Q2.textColor=[UIColor redColor]; } else if([yearLabel.text isEqualToString:@"Year"]) { errorLabel.text=@"Please Select the Highlighted Answers"; Q3.textColor=[UIColor redColor]; } else { [self submitSurveyAnswers]; [self submitSurveyAnswersOne]; [self submitSurveyAnswersTwo]; OnlineViewController*targetController=[[OnlineViewController alloc]init]; targetController.mynumber=mynumber; [self.navigationController pushViewController:targetController animated:YES]; } }
答案 0 :(得分:0)
尝试从else
中移除else if
,然后逐个进入所有条件.... Else if
将暗示如果一个陈述满足,那么其他人将被默认跳过。
if ([professionLabel.text isEqualToString:@"Profession"]) {
errorLabel.text=@"Please Select the Highliteg Answers";
Q1.textColor=[UIColor redColor];
}
if ([workLabel.text isEqualToString:@"Work"]) {
errorLabel.text=@"Please Select the Highliteg Answers";
Q2.textColor=[UIColor redColor];
}
if([yearLabel.text isEqualToString:@"Year"]){
errorLabel.text=@"Please Select the Highliteg Answers";
Q3.textColor=[UIColor redColor];
}