UITextFieldDelegate 事件延迟
这是一个奇怪的问题,但我对如何解决这个问题感到困惑 - 我有一个具有自定义 UITableViewCells 的 UITableView。每个 UITableViewCell
都有两个 UITextFields
,每个 UITextField
都链接到处理 textFieldDidEndEditing
事件的委托。除一种情况外,这完全有效。
问题
屏幕还有一个“保存”按钮,当用户编辑 UITextField
并直接单击“保存”按钮而不单击屏幕中的其他位置时,就会出现问题。在此类事件中,saveAction
方法会在 textFieldDidEndEditing
事件之前调用,因此用户的最后一次编辑会丢失。
我尝试使用 NSLog 语句进行调试,发现虽然 textFieldDidEndEditing
确实被调用,但它是在 saveAction
事件之后调用的。
我考虑过从 saveAction
调用 textFieldDidEndEditing
事件,但这没有意义,因为我不知道正在编辑哪个 UITextField
。
非常感谢任何建议。
This is a strange problem but I am perplexed on how to solve this - I have a UITableView
that has custom UITableViewCells. Each UITableViewCell
has two UITextFields
and each UITextField
is linked to a delegate that processes the textFieldDidEndEditing
event. This works perfectly except in one instance.
Problem
The screen also has a 'Save' button and the problem arises when the user edits a UITextField
and directly clicks the 'Save' button without clicking elsewhere in the screen. In such an event, the saveAction
method is invoked before the textFieldDidEndEditing
event and as a result the last edit of the user is lost.
I tried to debug using NSLog statements and found that while the textFieldDidEndEditing
is indeed getting called, it is called after the saveAction
event.
I thought about calling the textFieldDidEndEditing
event from saveAction
but that didnt make sense as I would have no idea about which UITextField
is being edited.
Any suggestions are very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以记下在视图控制器中调用 –textFieldDidBeginEditing: 委托方法时处于活动状态的文本字段
,并有一个指向活动文本字段的指定属性,然后在 -saveAction 中将其发送到 -resignFirstResponder。
标头:
m 文件:
you could make a note of the text field that is active when the –textFieldDidBeginEditing: delegate method is called in your view controller
have an assigned property that points to the active text field and then in -saveAction send it -resignFirstResponder.
header:
m file: