为什么 UITextField 清除按钮在 iOS 5 WeeApp 中不起作用?
我正在使用 iOSOpenDev 为通知中心制作一个 weeapp。我在 UIView
上有一个 UITextField
,并实现了 UITextFieldDelegate
协议。
我的问题是,单击 UITextField 中的清除按钮时永远不会调用 textFieldShouldClear
方法。其他接口方法(例如 shouldChangeCharactersInRange 和 textFieldShouldReturn)的调用不会出现问题。
有什么想法为什么接口方法永远不会被调用吗?
I'm making a weeapp for notification center using iOSOpenDev. I have a UITextField
on a UIView
and have implemented the UITextFieldDelegate
protocol.
My problem is that the textFieldShouldClear
method never gets called on clicking the clear button in the UITextField. Other interface methods such as shouldChangeCharactersInRange and textFieldShouldReturn are called without issue.
Any ideas why the interface method never gets called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当用户点击屏幕上的其他位置时我关闭键盘时遇到了这个问题。我有一个手势识别器寻找点击,当检测到点击时,它会在文本字段上调用 resignFirstResponder 。不幸的是,这打破了清除按钮。
我所做的是过滤点击以确保它们位于表格视图之外,由于必须手动触发按钮点击而稍微复杂:
I had this problem when I was dismissing the keyboard when the user tapped elsewhere on the screen. I had a gesture recognizer looking for taps, and when a tap was detected, it would call resignFirstResponder on the text field. Unfortunately, that breaks the clear button.
What I did was filter the taps to be sure they are outside the table view, slightly complicated by having to manually trigger button taps:
确保文本字段的委托是 self:
我听说 UIActionSheet 吸收了 UITextFieldDelegate 协议,并且通知中心可能会做同样的事情......
Make sure that the textfield's delegate is self:
I have heard that UIActionSheet sucks up the UITextFieldDelegate protocol, and the notification center might do the same...
按照 Graham Perks 的回答,我将 resignFirstResponder 调用更改为:
现在,键盘按预期自动隐藏在点击上,但清除按钮功能又回来了。
Following Graham Perks's answer, I changed my resignFirstResponder call to:
Now the keyboard is automatically hidden on taps as intended, but the clear button functionality is back.