UITextField valueDidChange-事件
有没有办法捕获文本字段的“valueDidChange”事件? oO
我有一个带有 UITextField 的 modalView 。
当 UITextField 为空时,应禁用导航栏中的“完成”按钮 当输入文本时,它应该被启用。
目前,实现此目的的唯一方法是使用“textFieldShouldReturn”方法。 这可行,但对于可用性来说简直太糟糕了。
有没有办法在每次输入或删除字母时检查要求?
Is there a way to catch a "valueDidChange"-Event for a Textfield? oO
I've got a modalView with an UITextField.
When the UITextField is empty, the "Done"-Button in the NavigationBar should be disabled
and when there is Text entered, it should become enabled.
Right now the only way to accomplish this by using the "textFieldShouldReturn"-Method.
This works but is simply horrible for usability.
Isn't there a way to check the requirements every time a letter is being entered or removed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实现
-textField:shouldChangeCharactersInRange:replacementString:
。Implement
-textField:shouldChangeCharactersInRange:replacementString:
.如果有人关心:解决方案是使用 addTarget:selector:controlevent: 捕获控件事件“EditingChanged”:;)
If anybody cares: the solution is to catch the control event "EditingChanged" with addTarget:selector:controlevent: ;)
我有一个带有
self.editButtonItem
的UITableViewController
,仅当UITextField.text
中有文本时才启用它。这是一种确保用户在用某些内容填充此UITextField
之前不会按“完成”的方法。我认为这正是您正在寻找的。我是这样做的:希望有帮助
I have a
UITableViewController
withself.editButtonItem
which is enabled only if theUITextField.text
has text in it. It's a way of ensuring that the user doesn't press "Done" before he/she has filled thisUITextField
with something. I think this is exactly what you're looking for. Here's how I did it:I hope that helps