问题描述
我有一个 UITableViewController,其中每个单元格都包含一个 UITextView 位于每个单元格的顶部.自然地,当与 textBox 的交互开始时,键盘会出现,同时整个表格也会随着键盘的出现而向上滚动,从而导致 textBox 消失.
I have a UITableViewController that each contains cells with a UITextView positioned at the top of each cell.Naturally when an interaction with the textBox begins, the keyboard will appear and at the same time the entire table will also scroll up along as the keyboard appears causing the textBox to go out of view.
因为我已经为我的 tableView 启用了分页,所以在向上滚动后它会再次向下滚动,以便文本框在视图中.
Because I've enabled pagination to my tableView so after scrolling up it will scroll down again so that the textBox is in view.
我想知道是否可以在键盘出现时禁用表格滚动,如果是,如何?
I would like to know if it is possible to disable the table from scrolling when the keyboard appears and if yes how?
推荐答案
自动滚动行为位于 UITableViewCONTROLLER 功能中.要禁用自动滚动,我找到了两种方法:
The autoscroll-behavior is located in the UITableViewCONTROLLER functionality. To disable the automatic scrolling I found two ways:
1) 使用 UIViewController 代替 UITableViewController - 自行设置数据源和委托
1) use instead of the UITableViewController simply a UIViewController - set the datasource and delegate on your own
2) 覆盖 viewWillAppear-Routine - 并且不要调用 [super viewWillAppear: animation]使用这两种解决方案,您不仅可以禁用 Autoscroll,还可以禁用其他一些不错但不是
2) Override the viewWillAppear-Routine - and DON´T call [super viewWillAppear: animated]With both solution you disable not only the Autoscroll, but also some other nice but not
基本功能,在 Apple 的类参考概述中有所描述:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewController_Class/Reference/Reference.html
essential features, that are described in the overview of Apple´s class reference: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewController_Class/Reference/Reference.html
这篇关于出现键盘时如何阻止 tableView 滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!