使用 DecimalPad 时如何关闭键盘
我有一个 UITableView
,其中包含一个带有 TextField
的自定义单元格。我出现了DecimalPad,众所周知,没有完成键。当我在普通 UIView 上有一个“仅十进制”文本字段时,我之前通过处理 TouchesEnded
事件,然后检查 TextField
是否为第一响应者,如果是这样,它将辞职,但如果该技术现在可以工作,那么我无法弄清楚我应该使用谁的 TouchesEnded
(UIView
一切都呈现在 UITableView、Cell、CellControler、TextField 上。我想我已经尝试了一切)。
我希望有另一种更干净的方法来处理这个问题。
有人吗?
I have a UITableView
with a custom cell that has a TextField
. I have the DecimalPad comes up, and as we all know, there is no done key. I previously had resolved this type of issue when I had a "Decimal only" textfield on a normal UIView by handling the TouchesEnded
event and then checking to see if the TextField
was the first responder and if so, it would then resign, but if that technique could work now then I'm not able to figure out who's TouchesEnded
I should be using (The UIView
that everything is presented on, the UITableView
, the Cell, the CellControler, the TextField.. I think I've tried everything).
I'm hoping there's another, cleaner way of dealing with this.
Anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为大卫有最好的主意 - 这是一些 Monotouch 代码可以帮助您入门。您需要将其放入显示小数点的视图控制器中:
I think David has the best idea - here is some Monotouch code to get you started. You will need to put this in the View Controller where the decimal pad is being shown:
如果您的目标是 iOS 4.0 或更高版本,则可以创建 inputAccessoryView 包含一个附加到键盘的“完成”按钮,点击该按钮将关闭键盘。 这里是来自有关创建简单 inputAccessoryView 的文档。
If you're targeting iOS 4.0 or greater you can create an inputAccessoryView containing a Done button to attach to the keyboard that will dismiss the keyboard when tapped. Here is an example from the documentation on creating a simple inputAccessoryView.
当用户点击背景时,您可以关闭它;我认为这是最直观的方式。
在 Interface Builder 中,将视图的类更改为
UIControl
。这是 UIView 的子类,因此您的程序将以相同的方式工作,但您还可以获得标准触摸事件。从这里开始很简单,为 Touch Down 事件创建一个方法:
[numberField resignFirstResponder]
当然,它可能与 MonoTouch 略有不同 - 不幸的是我对此了解不多,但希望提供帮助。
希望您可以使用这个概念,并相应地修改您的代码。
You could dismiss it when the user taps on the background; I think that's the most intuitive way.
In Interface Builder, change your View's class to
UIControl
. This is a subclass ofUIView
, so your program will work the same way, but you also get the standard touch events.From here it's simple, create a method for the Touch Down event:
[numberField resignFirstResponder]
Of course it might be slightly different with MonoTouch -- unfortunately I don't know much about it, but wanted to help.
Hopefully you can use the concept, and modify your code accordingly.
或者您可以在主视图中添加一些手势。
例如:
Or you may just add some gesture to your main view.
For example: