当从 UISplitViewController 显示时,UITableViewController 自动滚动停止考虑键盘 [英] UITableViewController auto-scrolling stops taking into account keyboard when shown from a UISplitViewController

查看:27
本文介绍了当从 UISplitViewController 显示时,UITableViewController 自动滚动停止考虑键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您子类化 UITableViewController 时,您通常会免费"获得某些行为.例如,当表格视图中的文本字段成为第一响应者时,视图控制器会自动滚动以确保该字段完全可见.

When you subclass UITableViewController, you normally get certain behaviors "for free". For example, when a text field in your table view becomes first responder, the view controller automatically scrolls itself to ensure the field is fully visible.

然而,当表视图控制器是 UISplitViewController 的详细视图控制器时,这种自动滚动不再考虑键盘的存在.表视图控制器仍会自动滚动以将文本字段保持在屏幕边界内,但它不再滚动以防止该字段被键盘覆盖.

However, when the table view controller is the detail view controller of a UISplitViewController, this auto-scrolling no longer takes into account the presence of the keyboard. The table view controller will still auto-scroll to keep the text field within the bounds of the screen, but it no longer scrolls to keep the field from being covered by the keyboard.

您可以通过使用 Xcode 的主从应用程序"模板创建一个新项目来自己测试,并将详细视图控制器替换为显示带有文本字段的单元格的表视图控制器.

You can test this yourself by creating a new project using Xcode's "Master-Detail Application" template, and replacing the detail view controller with a table view controller that displays cells with text fields in them.

我想了解为什么在这种情况下自动滚动会停止考虑键盘,如果可能的话,如何在不必自己复制自动滚动功能的情况下纠正这个问题.顺便说一句,这与覆盖 viewWillAppear 无关(就像这里关于表视图控制器自动滚动的其他一些问题一样).

I would like to understand why the auto-scrolling stops accounting for the keyboard in this case, and if possible how to rectify that without having to duplicate the auto-scrolling functionality myself. BTW, this has nothing to do with overriding viewWillAppear (as in some other questions here about table view controller auto-scrolling).

推荐答案

我知道为时已晚,但这可能会帮助遇到此问题的其他人.当我在 UITableViewCell 中添加文本字段时,这也发生在我身上.我所做的是删除

I know its late but this might help others who are having this issue. This happens to me as well when I added textfield in UITableViewCell. What I did was to remove

superViewWilAppear:动画

superViewWilAppear:animated

viewWillAppear 方法中的一行.所以方法看起来像这样

line in viewWillAppear method.So the method looks like this

-(void)viewWillAppear:(BOOL)animated{
    //[superViewWilAppear:animated];
     Your rest of code
} 

但是这样做是将自动滚动一起删除,并且当 textField 开始编辑时,您必须管理 UITableView 的滚动.不知道这是否解决了您的问题,但它会为您省去考虑不同设备的键盘高度的麻烦,并且最好自行管理.此外,我不确定这是否是正确的方法,但它对我有用.

But what this does is it removes the auto scrolling all together and you have to manage the scrolling of UITableView when textField starts editing. Don't know if this solved your problem but it will save you the trouble of considering keyboard height for different devices and its better to manage on your own. Also I am not sure if this is the right way to do it but it worked for me.

这篇关于当从 UISplitViewController 显示时,UITableViewController 自动滚动停止考虑键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆