0

クリックすると警告ボックスが表示される保存ボタンがあります。ユーザーにボックスにデータを入力してもらいたいのですが、データを入力せずに[OK]を押すと、警告ボックスのテキストフィールドを赤くしたい、つまり必須です。今のところ、別の警告ボックスを表示しています。助けてください。ありがとうございます。以下はコードです。

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

 }
4

3 に答える 3

0

これを試しましたか?

textField.textColor = [UIColor redColor];
于 2013-03-08T11:33:40.020 に答える
0

あなたができることは、以下のコードでalertViewのtextFieldのインスタンスを見つけることです

UITextField *alertTextField = (UITextField*)[alertView viewWithTag:REFERENCE_FIELD];

そして、このコードで赤に色を表示するコードを配置するだけです

[alertTextField setBackgroundColor:[UIColor redColor]];

これで問題が解決しますように:)

于 2013-03-08T11:34:48.940 に答える
0

これを試して:

- (BOOL) alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    UITextField *textField1 = [alertView textFieldAtIndex:0];
    [textField1 setDelegate:self];
    NSString *inputText = [[alertView textFieldAtIndex:0]text];
    if ([inputText length] == 7) // If it's 7 chars long, enable the button.
    {
        NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet]; // Only allow numbers

        if ([inputText rangeOfCharacterFromSet:set].location != NSNotFound) { //Not a Number?

            //show alert view here
            textField1.backgroundColor = [UIColor redColor];
            alertView.message = @"Only enter numbers please!";
            return NO;
        }
        alertView.message = @"Fill in your number:";
        return YES;

    } else {
        alertView.message = @"Fill in your number:";
        textField1.backgroundColor = [UIColor clearColor];
        return NO;
    }

}

あなたはそれをあなたのニーズに適応させることができます

于 2013-03-08T11:36:17.047 に答える