成为FirstResponder会使应用变慢 [英] becomeFirstResponder slows down app

查看:38
本文介绍了成为FirstResponder会使应用变慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个用于输入用户名和密码的文本字段和一个提交按钮.当按下提交按钮时,将执行检查以查看是否键入了用户名和密码.如果不是,它将显示一条警报消息,并且未输入值的字段将成为第一响应者.

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

我观察到,单击该按钮时,该按钮保持选中状态约1.5秒钟,然后显示警报.如果我注释掉 becomeFirstResponder 方法,则该方法可以不间断地工作.但是我需要 becomeFirstResponder 在那里.如何使用此功能加快速度?

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?

推荐答案

切换beginFirstResponder和showAlert的顺序.

Switch the ordering of becomeFirstResponder and showAlert.

这篇关于成为FirstResponder会使应用变慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆