首页 > 代码库 > UITextField next/go, keyboard delay

UITextField next/go, keyboard delay

问题一: 

总共三个UITextField, originalPwd/inputedPwd 键盘显示next,confirmedPwd键盘显示Go:

@property (weak, nonatomic) IBOutlet UITextField *originalPwd;@property (weak, nonatomic) IBOutlet UITextField *inputedPwd;@property (weak, nonatomic) IBOutlet UITextField *confirmedPwd;

但是键盘上的next和go根本没有反应,在UITextFieldDelegate方法 textFieldShouldReturn加断点不进入。

解决:经检查,翻了一个低级错误,没有设置UITextField的delegate。。。。。。

 

问题二:

第一次点击UITextField时keyboard延迟大概3s,难以接受。

解决:在viewDidLoad中加入以下打码

   UITextField *field = [UITextField new];    [[[[UIApplication sharedApplication] windows] lastObject] addSubview:field];    [field becomeFirstResponder];    [field resignFirstResponder];    [field removeFromSuperview];

ps:虽然keyboard不延迟了,但是整个View第一次加载延迟了, 改成如下:

    // resolve keyboard delay    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.0), dispatch_get_main_queue(), ^{        UITextField *field = [UITextField new];        [[[[UIApplication sharedApplication] windows] lastObject] addSubview:field];        [field becomeFirstResponder];        [field resignFirstResponder];        [field removeFromSuperview];    });