Bogdan Laukhin Bogdan Laukhin - 4 months ago 8
iOS Question

Keyboard for textfield appears after second tap (time to time)

I have one view in my app where there is 1 text field. And I've noticed that keyboard appears after second tap.

But it's interesting that on iPhone it's time to time (some time appears after first tap at once, and some time after second tap only).
On iPad looks like it more ofter appears after second tap only.


  • I use
    UITextFieldDelegate

  • in
    viewDidLoad
    I assign the delegate
    _locationTextField.delegate = self;

  • and I use delegate methods
    textFieldDidBeginEditing
    ,
    textFieldDidEndEditing
    ,
    textFieldShouldReturn



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


in storyboard
enter image description here

What could be the problem?

Answer

Found solution here on Stackoverflow - solution related with keyboard preload:

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

This method should be used in application: didFinishLaunchingWithOptions: method of AppDelegate.