Pregunta

In my add contact page, am validating my email textfield , phone number fields, etc. And am checking valid email on clicking all other textfields. So when i click on the phone number field, it will check email validity and show an alertview if email is invalid. So when i click ok button in the alertView, the cursor should go to the email textfield instead of being in the phone number field.. Can anyone help on this..?

¿Fue útil?

Solución 2

in alertview's delegate method,

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if([alertView isEqual:emailAlert])//emailAlert should be the instance variable
    {
       if(buttonIndex == 0)//assumes ok button index is 0
       {
             [textfield becomeFirstResponder];
       }
    }
}

Otros consejos

for making any textfield first responder. and you can do this in your alertview delegate.

[yourTxtField becomeFirstResponder];

Make your view controller implement the UIAlertViewDelegate, and add the current class as delegate to the shown alert view. In – alertView:clickedButtonAtIndex: make phone text field resign first responder and make the email text field befome first responder.

You can set AlertView's delegate and on click of "OK" button ,

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
      if (buttonIndex == 0) {
         [txtEmail becomeFirstResponder]; // your "Email" textField will get focused
    }
}

Try this way.. HTH :)

Make sure that you class conforms to UIAlertViewDelegate protocol and show the alert like

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Your Message" delegate:self cancelButtonTitle:@"cancel " otherButtonTitles:@"OK", nil];
[alert show];
[alert release];

implement the delegate method like

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 0)//ok button index is 0
       [textFieldEmail becomeFirstResponder];
} 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top