4

I have two textfields for username and password and a submit button. When the submit button is pressed a check is performed to see if the username and password was typed or not. If not it shows an alert message and the field whose value was not entered becomes the first responder.

-(IBAction)loginPressed:(id)sender {


    if ([username.text length] == 0)
    {
        [self showAlert:@"Invalid Username/ Password"];
       [username becomeFirstResponder];
        return;
    }

    if ([password.text length] == 0)
    {
        [self showAlert:@"Invalid Username/ Password"];
      [password becomeFirstResponder];
        return;
    }
}

I observed that on clicking the button, the button remains selected for about 1.5 seconds and then the alert is shown. If I comment out the becomeFirstResponder method, it works without any pause. However I need becomeFirstResponder to be there. How do I speed things up using this?

HG's
  • 818
  • 6
  • 22

2 Answers2

5

Switch the ordering of becomeFirstResponder and showAlert.

Frank Schmitt
  • 30,195
  • 12
  • 73
  • 107
  • 1
    I have the same problem with no alert :(. Massive delay (several seconds!) to call becomeFirstResponder. – Adam Oct 19 '11 at 12:21
  • I'm having the same issue too, with no alert - just unhiding a view/textfield, and then calling becomeFirstResponder. Any ideas? – G.S. Sep 13 '12 at 18:00
0

[self showAlert:@"Invalid Username/ Password"]; will take a time. you cant speeup that thing.

Rakesh Bhatt
  • 4,606
  • 3
  • 25
  • 38
  • But according to the OP, there is no delay if the becomeFirstResponder is removed, so apparently, showAlert is not the issue here. – Frank Schmitt Apr 12 '11 at 06:21