0

For some reason when I run my app on an iPad, tapping UITextFields in order to fill in data causes the entire app to freeze for a number of seconds. I was browsing Stack, and a similar question answered said it might be because I'm running textFieldShouldEndEditing on a back thread? But I'm running mine on a main thread:

   -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    dispatch_async(dispatch_get_main_queue(), ^{
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    });

    return YES;
}

Any idea what could be causing the freeze?

Community
  • 1
  • 1
Brittany
  • 1,359
  • 4
  • 24
  • 63
  • If you create a self contained, simple demo/test app and add the code above - does it show the same behavior? – Krumelur Feb 13 '16 at 20:48
  • Is it only the first time the keyboard appears? If so, have you tried running the app not under the debugger? There is a known issue where the keyboard appearance is delayed the first time when debugging – Paulw11 Feb 13 '16 at 20:56
  • @Krumelur Yes :/ Super strange. Created a brand new test app, same lagging issue when tapping text fields. – Brittany Feb 13 '16 at 20:56
  • @Paulw11 In my test/self contained demo app, it only happens the first time I tap the text field. However in my actual app, the slow/lag issue happens every time I tap a textfield. – Brittany Feb 13 '16 at 20:57
  • @Krumelur Worse yet, after tapping a text field, when it finally opens and I dismiss my keyboard, I can't tap any other buttons on the screen after. – Brittany Feb 13 '16 at 20:59
  • Why are you adding keyboard observation in the `didBeginEditing` method? Also, There is no need to dispatch `addObserver` on the main queue and you will already be on the main queue because this is a UI delegate method – Paulw11 Feb 13 '16 at 21:01
  • @Paulw11 ...So you're a genius. Lol. Removed it, works like a charm. Thank you! That said - while the slow loading time is a known issue for the first UITextField tap, is there a way to get rid of that issue? – Brittany Feb 13 '16 at 21:03
  • Here http://stackoverflow.com/questions/9108245/ios-how-can-i-preload-the-keyboard and here http://stackoverflow.com/questions/9357026/super-slow-lag-delay-on-initial-keyboard-animation-of-uitextfield/20436797#20436797 – Paulw11 Feb 13 '16 at 21:12
  • @Paulw11 Fixed! Your rock - thank you. – Brittany Feb 13 '16 at 21:45

0 Answers0