有一种方法可以告诉用户何时完成按时间间隔的输入?
我想知道是否有办法判断用户是否在 2 秒内没有在 UITextField
中输入内容。
如果这是不可能的,我想知道是否有一种方法可以判断用户是否在文本字段中输入错误 - 例如:
有一个 UITextView
,其中包含来自 的对象>NSArray
并且用户必须在文本字段中键入并匹配文本视图上的内容。如果他们犯了错误,它会告诉他们(我需要什么帮助) - 注意:如果用户正确输入字符串,它会自动接受它并继续下一个 - 没有提交字符串的按钮 - 它通过文本字段执行此操作。
I am wondering if there is a way to tell if the user hasn't typed in the UITextField
say for 2 seconds.
If that's not possible, I'd like to know if there is a way to tell if the user made an error typing in the text field - example:
There is a UITextView
which contains objects from an NSArray
and the user has to type in the textfield and match the content on the text view. If they make a mistake, it will tell them (what I need help with) - Note: if the user types the string correctly, it automatically accepts it and goes on to the next one - there is no button to submit the string - it does that via the text field.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
无论您在何处处理文本更改,都可以启动
NSTimer
。如果在计时器触发之前输入了更多文本,您可以对其调用-invalidate
来取消它,但如果计时器触发,则您知道尚未输入任何文本。Wherever you're handling the change of text, you can start an
NSTimer
. If more text is entered before the timer fires, you can call-invalidate
on it to cancel it, but if the timer fires then you know no text has been entered.这是可能的,但需要做一些工作。您需要查看 NTimer 和 NSDate 类以及 UITextFieldDelegate 协议。基本上,每次用户在文本字段中输入内容时,您都会触发一个委托方法。然后该方法缓存当前时间(通过 [NSDate date])并启动一个持续时间为两秒的计时器。当计时器触发时,您可以触发一个方法来检查缓存的 NSDate,以查看文本字段中的最后一次输入是否是在过去两秒内。
This is possible, but it is going to involve some work. You will need to check out the NSTimer and NSDate classes and the UITextFieldDelegate protocol. Basically, every time the user enters something into the text field, you get a delegate method to fire. That method then caches the current time (via [NSDate date]) and starts a timer with a two-second duration. When the timer fires, you have it trigger a method that checks the cached NSDate to see if the last input into the text field was within the last two seconds.
查看
UITextFile
和UITextView
的委托方法。您可以实现多种方法,当用户更改字段的状态时会调用这些方法。此外,如果您需要特定时间间隔的某些内容,您可以启动NSTimer
。Check out the delegate methods for
UITextFile
andUITextView
. There are several methods you can implement that are called when the user changes the state of the field. In addition, you can fire offNSTimer
if you need something for a particular interval.注册文本字段上的文本更改事件。当发生变化时,创建或更新计时器成员。如果计时器触发,则表明您的时间已过。清理时,使计时器无效。
Register for text changed events on the text field. When a change occurs, create or update a timer member. If the timer fires, your time has elapsed. When cleaning up, invalidate the timer.