2

这里有一个非常奇怪的问题,这在 iOS 7 之前没有发生过......

我在我创建的表单中有一个 uitextfield 和 uitextview ...问题是如果用户将文本字段作为第一响应者然后点击 uitextview 发生死锁,内存将增加,直到看门狗杀死我的应用程序..

当我从 uitextview 更改为 uitextfield 时,不会发生这种情况

相关代码:

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

}

没有什么比这更...

如果我先辞去第一响应者,这个问题不会发生,但它会让用户点击 textview 两次,这是不希望的..

死锁也发生在 textview:didEndEditing 上,(好像 textview 是放弃键盘而不是 textfield 的那个,也调用了 textfield:didEndEditing).. textview:didEndEditing 不应在任何地方调用

这真的让我大吃一惊……有什么建议吗?

4

2 回答 2

1

我只是通过修改 DAKeyboardControl.m 中的 inputKeyboardDidShow 方法来修复它,如下所示:

- (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];
    }
}
于 2014-09-12T03:34:54.097 回答
0

好的,我知道有什么问题

当键盘出现时,我正在使用 DaKeyboardControl 来调整视图......奇怪的是,在 iOS 7 上,当更改第一响应者时,这似乎被打破了(当只有一个 textview/textfield 存在时,它不会进入死锁).. .我正在向他们的 githubs 打开一个 BUG 报告,同时我想知道哪一行产生了这个错误......当我有它时,我会在编辑时与你分享

编辑:问题出在 UIKeyboardWillShowNotification 接收器上...此通知被多次调用...解决方案似乎是使用 UIKeyboardDidChangeFrameNotification 或 UIKeyboardWillChangeFrameNotification 来执行帧更改...

我希望这可以帮助某人...不知道使用 UIKeyboardWillShowNotification 是否会给现在不使用 iOS 7 的人带来问题

于 2013-09-21T19:39:46.077 回答