Search code examples
iosobjective-cuitextfielduitextfielddelegate

How to move focus on to a Textfield after an alertView from another textField


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..?


Solution

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