2 つのことを行う必要があります。1) キーボードでカバーされていない画面の表示部分にテーブル ビューが収まるようにします。2) テーブルを最後の行までスクロールします。
ビューのサイズを変更するには、表示されるキーボードを検出するように登録します。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector (keyBoardWillShow:)
name: UIKeyboardWillShowNotification object: nil];
このkeyBoardWillShow:
メソッドは、キーボードが表示され、テーブルビューのサイズを変更できるときに呼び出されます。
- (void)keyBoardWillShow:(NSNotification *)aNotification
{
NSValue *value = [[aNotification userInfo] objectForKey: UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [value CGRectValue];
CGFrame tableFrame = self.tableView.frame;
tableFrame.height -= keyboardRect.size.height
self.tableView.frame = tableFrame;
}
最後に、最後のセルまでスクロールします (必要にkeyBoardWillShow:
応じてこれを実行できます)。
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:lastRowIndex inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];