使表格视图内的 UITextField 可见滚动
我有一个 UITableViewController,一堆部分和行,对于每一行,我添加了一个 UITextField 作为子视图,在行本身中右对齐。
如果用户点击该行,我会在本地保存索引路径,使相应的文本字段成为第一响应者,最后,当键盘出现时,我使表视图滚动,以便该行保持可见。
当用户点击文本字段时,我面临着获得相同行为的问题。在这种情况下,不会调用 didSelectRowAtIndexPath: 方法,因此我不知道如何告诉表视图滚动以确保“选定”行仍然可见。
整个过程可能不正确。你知道解决的方法吗?
多谢!
I have a UITableViewController, a bunch of sections and rows, and for each row I added a UITextField as a subview, right aligned in the row itself.
If the users taps on the row, I locally save the indexPath, make the corresponding text field become the first responder and finally, when the keyboard appears, I make the table view scroll so that the row remains visible.
I am facing the problem to obtain the same behaviour when the user taps the text field instead. In this case the didSelectRowAtIndexPath: method isn't called, so I do not know how to tell the table view to scroll to make sure that the "selected" row is still visible.
Probably the whole process is not correct. Do you know a way to solve it?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此不太确定,但是...
将
UITextField
的userInteractionEnabled
属性设置为NO
。这样,触摸就会“穿过”控件,点击UITableViewCell
。调用didSelectRowAtIndexPath:
时,将UITextField
的userInteractionEnabled
属性设置为YES
。编辑完成后,将其改回NO
。I'm not absolutely sure about this, but...
Set the
userInteractionEnabled
property of theUITextField
toNO
. This way, the touch goes "through" the control, tapping theUITableViewCell
. WhendidSelectRowAtIndexPath:
is called, set theuserInteractionEnabled
property of theUITextField
toYES
. When the editing is complete, change it back toNO
.