danielamitay / DAKeyboardControl

DAKeyboardControl adds keyboard awareness and scrolling dismissal (ala iMessages app) to any view with only 1 line of code.
Other
1.58k stars 214 forks source link

In iOS7 self.keyboardActiveInput results in EXC_BAD_ACCESS for a UITextView #57

Closed schuler1 closed 10 years ago

schuler1 commented 10 years ago

I am using a UITextView in one of my App's controllers which doesn't rely on the functionality provided by DAKeyboardControl.

When the view containing the UITextView is presented I force the keyboard to appear right away by [self.textView becomeFirstResponder] in viewWillAppear.

This works fine in iOS5 and iOS6. However, in iOS7 this results in a crash which I traced to:

Some debugging shows that keyboardActiveInput has a stale value.

I have two workarounds for this issue:

1) call becomeFirstResponder in viewDidAppear 2) the following code in viewWillAppear

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.textView becomeFirstResponder];
    });
}
else {
    [self.textView becomeFirstResponder];
}

Both solutions work with the caveat that the keyboard does not appear right away which is not desirable. This appears to be an Apple issue but I am letting you know in case you have some insight which would cause this problem in iOS7. Note that if I exclude DAKeyboardControl support from my App which I can do through a #define, the problem does not surface at all.

My apologies in advance if this is a duplicate issue or ignorance on my part.

Best regards,

Sergio

chrisballinger commented 10 years ago

I am experiencing the same crash on 2.3.0 but your workaround doesn't seem to work for me

edit: Fixed it by doing this:

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.view removeKeyboardControl];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
...
schuler1 commented 10 years ago

Clearly a problem in my code. Thanks for your input Chris.