フォームの「送信」ボタンが押されたときに呼び出されるメソッド-(void)validateFormInput:(UITextField *)textFieldがあります。このメソッドは次のことを行います。
1)指定されたtextFieldのテキストを検証します。2)無効な場合は、アラートボックスをポップアップし、UITextFieldの周囲に赤い境界線を描画して、そのUITextFieldにフォーカスを戻します。
問題は、無効なUITextFieldにフォーカスが戻らないことです。
検証方法は次のとおりです-なぜこれが無効なUITextFieldに焦点を戻さないのですか?
ありがとう!
//Called when form "submit" button is pressed
-(void)validateFormInput:(UITextField *)textField{
//If Validation fails...
if([textField.text length] <1){
//simple test case
textField.layer.borderWidth = 2.0f;
textField.layer.borderColor = [[UIColor redColor] CGColor];
textField.layer.cornerRadius = 5;
textField.clipsToBounds = YES;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Please add a title"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
alert = nil;
[textField becomeFirstResponder];
}
}