为什么 UITableView 不能“自动滚动”?编辑 UITextField 时(在 UITableViewCell 中)? (iPhone)
我创建了一个 UITableView
,其类型为 UITableViewStyleGrouped
。然后我创建了几个不同的部分,每个部分有几行。在每一行中,我都创建了一个包含 UITextField
的自定义 UITableViewCell
。我还有一个包含 UITextView
的 UITableViewCell
。
我还实现了一个出现在 UIKeyboard
顶部的 UIToolbar
,允许用户通过按 在 UITextField
之间移动上一个或下一个。
我遇到的问题有两个:
- 我需要 UITableView 滚动,以便当下一个
UITextField
(或UITextView
)成为第一个响应者时,它是可见的(甚至并显示键盘)。 - 当选择
UITextField
(或UITextView
)(不使用上一个和下一个按钮)时,应该进行调整该字段在键盘上方可见。
我浏览了很多不同的教程,但没有一个能解决我的问题。如果您能提供任何帮助,我们将不胜感激。
其他信息:
我100%确定我的应用过去会自动执行上述所有操作,但我似乎已停止这样做现在我不明白为什么。发生这种情况有什么原因吗?是否有一些功能或我可能改变的东西会破坏这种行为?
I have created a UITableView
that is of type UITableViewStyleGrouped
. I have then created several different sections with a few rows in each. Within each of these rows I have created a custom UITableViewCell
that contains a UITextField
. I also have one UITableViewCell
that contains a UITextView
.
I have also implemented a UIToolbar
that appears on top of the UIKeyboard
that allows the user to move through the UITextField
's by pressing previous or next.
The issue I'm having is two-fold:
- I need the UITableView to scroll so that when the next
UITextField
(orUITextView
) becomes the first responder it is visible (even with the keyboard being displayed). - When a
UITextField
(orUITextView
) is selected (without using the previous and next buttons) is should adjust so that the field is visible above the keyboard.
I have looked around at lots of different tutorials however none of them have resolved my issue. Any help you could offer would be hugely appreciated.
ADDITIONAL INFO:
I'm 100% certain that my app used to do all of the above automatically, however I seems to have stopped doing it now and I don't understand why. Is there a reason why this may of happened? Is there some function or something that I may have changed that would destroy this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
现在可能对原始海报没有用处,但是那些遇到这样的问题的人,它曾经工作过,然后停止了......
没有:
检查你的 UITableViewController 子类中
!在 UITableViewController 中使用 viewWillAppear 会破坏“键盘出现时自动向上滚动的 tableView”行为。
我只是通过费力地比较一个项目的旧版本(它确实可以工作)和我的最新源(它已经停止工作)来发现这一点。
Probably no use to original poster now, but those having an issue like this where it once did work and then stopped...
check you don't have a:
in your UITableViewController subclass!!!
using viewWillAppear in a UITableViewController breaks the "automagic tableView scrolling up when keyboard appears" behaviour.
I only found this by comparing laboriously an old version of a project where it did work with my latest source where it had stopped working.
查看 TaggedLocations< /a> 来自苹果的示例代码。它可以做同样的事情,无需任何额外的操作。
关键是您的视图控制器遵循标准。也就是说,您没有有容器视图控制器,例如 UIViewController 中的 UINavigationController。
Check out TaggedLocations sample code from apple. It does the same thing without any extra manipulation.
The key is that your viewcontrollers are following the standard. i.e you are NOT having container viewcontrollers such as UINavigationController within UIViewController.
您必须以编程方式自己更新 tableview Frame...
并且我 100% 确定,如果您 100% 确定您的应用程序曾经自动执行上述所有操作...那么它不是您的应用程序。
检查文档...这里是链接
<一href="https://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/ManageTextFieldTextViews/ManageTextFieldTextViews.html#//apple_ref/doc/uid/TP40009542-CH10-SW1" rel =“nofollow”> https://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/ManageTextFieldTextViews/ManageTextFieldTextViews.html#//apple_ref/doc/uid/TP40009542-CH10-SW1
您必须注册键盘通知..然后更新您的表格视图框架。
对于下一个和上一个......您必须以编程方式检查哪个文本字段变为活动状态......然后相应地设置框架。
You have to update tableview Frame yourself programatically...
and i am 100% sure that if you are 100% certain that your app used to do all of the above automatically ...than it is not your app.
Check the docs..here is the link
https://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/ManageTextFieldTextViews/ManageTextFieldTextViews.html#//apple_ref/doc/uid/TP40009542-CH10-SW1
You will have to register for keyboard notifications..and then update your tableview frame.
And for next and previous.. you have to programmatically check which textfield became active..and then set the frame accordingly.