将第一响应者从uitextfield更改为uitextview时的死锁[iOS 7] [英] Deadlock when changing first responder from uitextfield to uitextview [iOS 7]

查看:181
本文介绍了将第一响应者从uitextfield更改为uitextview时的死锁[iOS 7]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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..

这样做当我从uitextview更改为uitextfield时没有发生

This does not happen when I change from uitextview to 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;
}

}

除此之外没有什么比那... ...

There is nothing more to this than that...

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

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..

此外,textview上发生了死锁:didEndEditing,(就好像textview是辞退键盘而不是textfield的那个,textfield:didEndEditing也被调用了).. textview:didEndEditing不应该在任何地方都可以打电话

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?

推荐答案

好的我有什么问题

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

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

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

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...

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

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

这篇关于将第一响应者从uitextfield更改为uitextview时的死锁[iOS 7]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆