2014-07-02 54 views
0

我在單元格中使用帶有textField和文本視圖的UITableviewController。默認情況下,當我點擊一個文本框時,tableviewcontroller向上滾動內容讓我選擇該字段的內容。這個默認行爲非常有用,但是當我編輯textView時,我已經實現了一個帶有完成按鈕(inputAccessoryView)的工具欄。當我從編輯textField切換到編輯textView時,這是一個問題,因爲鍵盤的工具欄剛好在textView上方。UITableViewController滾動默認行爲

我已經嘗試了很多解決方案,但沒有爲我工作。我試過這樣的:https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

但不適合我,因爲我想這個行爲已經在UITableViewController中實現。

PS:UITableViewController是使用Interface Builder創建的。我不知道這些信息是否有用。

回答

0

如果您設置的UITableViewController實施UITextViewDelegate協議,那麼你就可以知道你什麼時候開始通過實施這種方法編輯的TextView:

- (void)textViewDidBeginEditing:(UITextView *)textView 
{ 
    //then you can scroll the tableview up so you can see the textView 
    [self.tableView setContentOffset:CGPointMake(0, /*height of your toolbar*/) animated:YES]; 
} 
+0

非常感謝您! – Andorath