textFieldDidEndEditing 触发“太晚了”

发布于 2025-01-06 14:43:17 字数 475 浏览 0 评论 0原文

我有一个多视图流程,用户正在输入数据,并且我将其保存到模型类属性中的每一步。

我使用 textFieldDidEndEditing 检查输入是否有效,如果有效,则保存输入的数据。

在视图上,我有一个 continueButtonClicked 事件,用于检查所有验证是否通过,如果通过则加载下一个视图。我没有在这里设置模型的属性,因为我认为我不必这样做,因为每个字段一次保存到模型 1 字段。但是,我注意到一些问题。

如果用户位于文本框内并单击“继续”按钮,则 continueButtonClicked 事件会在 textFieldDidEndEditing 之前触发。最终发生的情况是,在 textFieldDidEndEditing 中进行保存之前,下一个视图将填充“旧”模型。

我缺少什么?将所有属性设置在“继续”上是否正确?如果我为网络编程,我就会这样做,但它似乎不适合本机应用程序。

I have a multiview process the user is entering in data and I'm saving it to the model class properties each step along the way.

I use textFieldDidEndEditing to check if the input is valid, and if so, saves the entered data.

On the view I have a continueButtonClicked event that checks to see if all the validations pass and if so loads the next view. I do NOT set the properties of the model here, because I think I shouldn't have to since each field is saved to the model 1 field at a time. However, I noticed some issues.

If the user is inside of a textbox and clicks the "Continue" button, the continueButtonClicked event fires BEFORE the textFieldDidEndEditing. What ends up happening is that the next view is populated with the "old" model prior to the save happening in textFieldDidEndEditing.

What am I missing? Is it proper to set all the properties on the Continue? That's how I would do it if I were programming for the web, but it doesn't seem right for a native app.

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

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

发布评论

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

评论(2

往事随风而去 2025-01-13 14:43:17

您可以在活动文本字段/文本视图(或所有这些)上调用 resignFirstResponder,这将触发 textFieldDidEndEditing

一般来说,对于此类文本编辑问题,另一种方法是滥用 -textField:shouldChangeCharactersInRange:... 委托方法,您可以在其中确定输入的每个字符的新值。仅当没有其他方法时才应恢复到此方法。

You can call resignFirstResponder on the active textfield/textview (or on all of them), which will trigger the textFieldDidEndEditing.

In general, for such text editing issues, another approach is to abuse the -textField:shouldChangeCharactersInRange:... delegate method, in which you can determine the new value for every character entered. You should only revert to this method if there is no other way.

隔纱相望 2025-01-13 14:43:17

您可以尝试一下这个方法,看看是否能解决您的问题?

textFieldShouldEndEditing:

Can you try this instead and see if that solves your problem?

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