becomeFirstResponder slows down app

半世苍凉 提交于 2019-12-23 12:35:38

问题


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?


回答1:


Switch the ordering of becomeFirstResponder and showAlert.




回答2:


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



来源:https://stackoverflow.com/questions/5631095/becomefirstresponder-slows-down-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!