tableView 中的 UITextField 和处理数字键盘
我有一个表格视图,每个单元格都有一个仅接受数值的文本字段。出于我的目的,我将自定义小数位添加到默认数字键盘。由于没有“完成”按钮来处理键盘,因此我在表格视图上添加了一个按钮。按钮背景的不透明值设置为零。当没有键盘时该按钮隐藏。当用户单击文本字段时,我取消隐藏该按钮。单击背景时,键盘将被释放,按钮将再次隐藏。这是有效的。 我的问题是: 1. 这是可以接受的消除键盘的解决方案吗?这似乎不是最好的方法。 2.使用此解决方案时,我遇到一个问题:如果用户在一个文本字段中输入,然后在另一个可见文本字段内单击,而不单击其他地方的背景,则会发生键盘被关闭的情况,因为事件被不可见的按钮捕获。用户应该能够继续在其他文本字段内进行编辑。现在,用户必须再次单击另一个文本字段并开始输入值。
有人有更好的建议吗?谢谢。
I have a table view with each cell having a text field accepting numeric values only. I added the custom decimal place to the default numeric keypad, for my purpose. Since there is no "Done" button to dispose the keypad, I added a button over the table view. The button's background's opaque value is set to zero. The button is hidden when there is no keypad. When a user clicks on the text field, I un-hide the button. On clicking on the background, the keypad is disposed and the button is hidden again. This is working.
My questions are:
1. Is this acceptable solution for dismissing the keypad? It does not seem to be the best way of doing it.
2. With this solution I have one problem: If a user enters in one text field and then clicks inside another visible text field without clicking on the background elsewhere, what happens is the keypad is dismissed since the event is caught by the invisible button. The user should be able to continue editing inside the other text field. Instead now the user has to once again click inside the other text field and start entering the values.
Any one has better suggestions? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,数字键盘中没有完成/返回按钮。
但是,如果您使用表格,那么您可以为所有文本字段设置标签,并根据所选文本字段设置表格框架以在中心显示。
关闭键盘的另一种可能方法是您可以设置对表滚动视图委托方法的退出调用。
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
因此,当用户滚动表格时,键盘将消失。
Yes in numeric keypad there is not done/return button.
But if you are using table then u can set tag to all textfields and set the frame of table accorading with selected textfield to display in center.
and another possible way to dismiss keypad is you can set resign call to table scrollview delegate method.
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
so when user scroll the table, keypad will dismissed.