文本字段响应程序不兼容 iOS4 -> iOS 5

发布于 2024-12-18 05:43:03 字数 1086 浏览 3 评论 0原文

奇怪的问题:

两个 UITextFields,由单个控制器管理,启用键盘输入。如果在字段 #1 中输入一个值并按 KB 上的“下一步”,闪烁的光标就会很好地跳转到字段 #2,一切正常。但是(仅在 iOS 5 中)如果触摸字段 #2 而不是按“下一步”,则光标会跳转到字段 #2 但不会闪烁,并且 KB 会显示死的。

单步执行代码,我发现第一种情况的顺序是:

  • textFieldShouldReturn:field#1 (它为 #1 做了一个辞职的第一响应者)
  • textFieldDidEndEditing:field#1 (它为 #1 做了一个辞职,并为 #1 做了一个成为) 2)
  • textFieldShouldBeginEditing:field#2

在第二种情况下(当触摸字段与使用“Next”时),序列为:

  • textFieldShouldBeginEditing:field#2
  • textFieldDidEndEditing:field#1
  • textFieldShouldBeginEditing:field#2 (再次)
  • textFieldDidEndEditing:field#2 (这对 #1 和 #2 都进行了辞职)

显然,当 #2 的辞职完成后会杀死 KB,但是 为什么 iOS 5 使用字段 #2 调用 DidEndEditing???如何才能规避这一点呢?

更新

添加了 textFieldShouldEndEditing 的挂钩。它在 field#1 的 textFieldDidEndEditing 之前调用,但不在 field#1 的 textFieldDidEndEditing 之前调用。不过,奇怪的是,textFieldShouldBeginEditing 是在 field#2 的 textFieldDidEndEditing 之前调用的。听起来像是 iOS 代码中彻头彻尾的“欺骗错误”。

更新 2

iOS 5 不处理 testFieldDidEndEditing 之外的 resign/become 调用。规避方法见下文。

Curious problem:

Two UITextFields, managed by a single controller, enabled for keyboard input. If one enters a value in field #1 and presses "Next" on the KB, the blinking cursor jumps to field #2 just fine and everything's OK. But (only in iOS 5) if one touches field #2 instead of pressing "Next", the cursor jumps to field #2 but doesn't blink and the KB is dead.

Stepping through the code, I find that in the first case the sequence is:

  • textFieldShouldReturn:field#1 (which does a resign first responder for #1)
  • textFieldDidEndEditing:field#1 (which does a resign for #1 and a become for #2)
  • textFieldShouldBeginEditing:field#2

In the second case (when the field is touched vs using "Next") the sequence is:

  • textFieldShouldBeginEditing:field#2
  • textFieldDidEndEditing:field#1
  • textFieldShouldBeginEditing:field#2 (again)
  • textFieldDidEndEditing:field#2 (which does a resign for BOTH #1 and #2)

Obviously, when the resign for #2 is done that kills the KB, but WHY is iOS 5 making the call to DidEndEditing with field #2??? And how could one circumvent this?

Update

Added a hook for textFieldShouldEndEditing. It's called before textFieldDidEndEditing for field#1, but not before textFieldDidEndEditing for field#1. Though, curiously, textFieldShouldBeginEditing is called just before textFieldDidEndEditing for field#2. Smells like an out-and-out "dupe error" in the iOS code.

Update 2

iOS 5 does not handle resign/become calls out of testFieldDidEndEditing. See below for circumvention.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏舞 2024-12-25 05:43:03

我得出的结论是,iOS 5 没有(正确)处理在 textFieldDidEndEditing 内进行 resignFirstResponder/becomeFirstResponder 调用的情况。将逻辑(或多或少)移至 textFieldShouldReturn (触摸会自行处理),现在似乎工作正常。

I came to the conclusion that iOS 5 does not (correctly) handle the case of having resignFirstResponder/becomeFirstResponder calls inside textFieldDidEndEditing. Moved the logic (more or less) to textFieldShouldReturn (touch kind of takes care of itself), and now it seems to work OK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文