第二次点击(不时)后出现文本字段键盘

时间:2016-05-06 09:18:45

标签: ios objective-c keyboard uitextfielddelegate

我的应用中有一个视图,其中有一个文本字段。而且我注意到第二次敲击后会出现键盘。

但有趣的是,在iPhone上有时间(有些时间会在第一次点击后出现,有些时间仅在第二次点击后出现)。 在iPad上,看起来只有在第二次点击后才出现更多内容。

  • 我使用UITextFieldDelegate

  • viewDidLoad
  • 我指派了代理人_locationTextField.delegate = self;

  • 我使用委托方法textFieldDidBeginEditingtextFieldDidEndEditingtextFieldShouldReturn

e.g:

#pragma mark -
#pragma mark UITextFieldDelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    _locationNameBeforeManualEdit = _locationTextField.text;
    // save the previod city value to compare after did end editing
    NSLog(@"textFieldDidBeginEditing");

}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    NSLog(@"textFieldDidEndEditing");

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self continueButtonPressed:nil];
    // [textField resignFirstResponder];
    return YES;
}
在故事板中

enter image description here

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

在Stackoverflow上找到解决方案 - 与键盘预加载相关的解决方案:

- (void)preloadKeyboard {
    UITextField *lagFreeField = [[UITextField alloc] init];
    [self.window addSubview:lagFreeField];
    [lagFreeField becomeFirstResponder];
    [lagFreeField resignFirstResponder];
    [lagFreeField removeFromSuperview]; 
}

此方法应在application: didFinishLaunchingWithOptions:的{​​{1}}方法中使用。