StartFirstResponder slows down the application

I have two text fields for username and password and submit button. When the submit button is pressed, a check is performed to determine if a username and password have been entered. If not, a warning message appears, and a field whose value has not been 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 noticed that when the button is pressed, the button remains selected for about 1.5 seconds, and then a warning is displayed. If I comment on the becomeFirstResponder method, it works without a pause. However, I need to becomeFirstResponder be there. How can I speed up the work?

+4
source share
2 answers

Toggle startFirstResponder and showAlert settings order.

+5
source

[self showAlert: @ "Invalid username / password"]; it will take some time. you cannot verify this.

0
source

Source: https://habr.com/ru/post/1347672/


All Articles