2
votes

have a really strange problem here, this did not happen before iOS 7...

i have a uitextfield and uitextview in a form that i created... the problem is that if the user has the textfield as first responder then taps on the uitextview a deadlock happens, memory will increase until the watchdog kills my app..

This does not happen when I change from uitextview to uitextfield

Relevant code:

#pragma mark - UITextView Delegate
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

if ([text isEqualToString:@"\n"]) {
    [textView resignFirstResponder];
}

NSUInteger newLength = [textView.text length] + [text length] - range.length;

return (newLength > 120) ? NO : YES;

}

-(void)textViewDidEndEditing:(UITextView *)textView {

if (textView.tag == CreatePlaceElementDescription) {
    self.marker.info = textView.text;
}
else if (textView.tag == CreatePlaceElementAddress) {
    self.marker.address = textView.text;
}
}

#pragma mark - UITextField Delegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

if ([string isEqualToString:@"\n"]) {
    [textField resignFirstResponder];
}

NSUInteger newLength = [textField.text length] + [string length] - range.length;

//Limit name textfield length
return (newLength > 60) ? NO : YES;
}

-(void)textFieldDidEndEditing:(UITextField *)textField {

if (textField.tag == CreatePlaceElementName) {
    self.marker.name = textField.text;
}

}

There is nothing more to this than that...

if i resign first responder first this problem won't happen but it will make the user tap the textview twice and that is undesired..

Also the deadlock happens on textview:didEndEditing, (as if the textview was the one resigning the keyboard not the textfield, textfield:didEndEditing is also called).. textview:didEndEditing should not be called anywhere

it really boggles my mind... any suggestions?

2
Any reason i'm being downvoted? please be helpful and at least tell me in which way i'm wrong... i have throughly tested all my app, and this error is really bugging my mind..Heavy_Bullets

2 Answers

1
votes

I just managed to fix it by modifying the method inputKeyboardDidShow in DAKeyboardControl.m like below:

- (void)inputKeyboardDidShow
{
    // Grab the keyboard view
    if(self.keyboardActiveInput.inputAccessoryView.superview){
        self.keyboardActiveView = self.keyboardActiveInput.inputAccessoryView.superview;
        self.keyboardActiveView.hidden = NO;
    }

    // If the active keyboard view could not be found (UITextViews...), try again
    if (!self.keyboardActiveView) {
        // Find the first responder on subviews and look re-assign first responder to it
        [self reAssignFirstResponder];
    }
}
0
votes

Ok i got what's the problem

i'm using DaKeyboardControl to adjust views when the keyboard appears... what's odd is that it seems this is broken on iOS 7 when changing first responders (it won't enter the deadlock when only one textview/textfield is present)... i'm opening a BUG report to their githubs while i figure which line is producing this error... when i have it i'll share it on a EDIT with you

EDIT: The problem is on the UIKeyboardWillShowNotification receivers... this notification gets called multiple times... the solution it seems is to use UIKeyboardDidChangeFrameNotification or UIKeyboardWillChangeFrameNotification to perform the change of frame...

I hope this can help someone... don't know if the use of UIKeyboardWillShowNotification will present problems to people not using iOS 7 now