当键盘出现时,如何阻止tableView滚动?

我有一个UITableViewController,每个都包含位于每个单元格顶部的UITextView的单元格。 当然,当与textBox的交互开始时,键盘将会出现,同时整个表格也会随着键盘的显示向上滚动,导致textBox不在视野范围内。

因为我已经为我的tableView启用了分页,所以在向上滚动之后它将再次向下滚动以便textBox在视图中。

我想知道是否有可能在键盘出现时禁用滚动表,如果是,如何?

autoscroll-behavior位于UITableViewCONTROLLERfunction中。 要禁用自动滚动,我发现了两种方法:

1)使用而不是UITableViewController只需一个UIViewController – 自己设置数据源和委托

2)覆盖viewWillAppear-Routine – 并且不要调用[super viewWillAppear:animated]使用这两个解决方案你不仅可以禁用Autoscroll,还可以禁用其他一些不错但不是

基本function,在Apple的类参考概述中描述: http : //developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewController_Class/Reference/Reference.html

我们可以通过多种方式禁用tableview滚动。

1)在textView委托方法中

 - (void)textViewDidBeginEditing:(UITextView *)textView{ tableView.scrollEnabled = NO; } - (void)textViewDidEndEditing:(UITextView *)textView{ tableView.scrollEnabled = YES; } 

2)键盘通知

 - (void)viewWillAppear:(BOOL)animated{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:self.view.window]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:self.view.window]; } - (void)viewWillDisappear:(BOOL)animated { // unregister for keyboard notifications while not visible. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];} - (void)keyboardWillShow:(NSNotification *)notif { tableView.scrollEnabled = NO; } - (void)keyboardWillHide:(NSNotification *)notif { tableView.scrollEnabled = YES; }