我有一个保存按钮,单击时会显示一个警告框。我希望用户在框中输入一些数据,如果他/她没有输入任何数据并按确定,我想让警告框文本字段变为红色,即表示它是强制性的。目前我正在显示另一个警报框。请帮助我,谢谢。以下是代码。
-(void) saveCalculaterData{
UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:REFERENCE_ID
message:@"\n\n"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
textField = [[UITextField alloc] initWithFrame:CGRectMake(12, 50, 260, 25)];
textField.tag=REFERENCE_FIELD;
[textField setBackgroundColor:[UIColor whiteColor]];
[textField setPlaceholder:ADD_REFERENCE_ID];
[prompt addSubview:textField];
[prompt show];
[textField becomeFirstResponder];
textField.delegate=self;
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex > 0) {
NSString *textValue = textField.text;
if ([textField.text length] <= 0)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"No Reference"
message: @"msg"
delegate: self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil,nil];
[alert show];
}
else{
CalculatorData *calcData = [self getCalcData];
calcData.dataKey = textValue;
if([database saveCalculatorData:(CalculatorData *)calcData tableName:[database Table]]){
[Utils showAlert:RECORD_SAVED];
}
}
}
}