2014-04-16 28 views
0

我在我的應用程序中有幾個UITableViewControllers。我在UITableViewCells中有一些UITextFields。有時tableView會在鍵盤出現時自行調整大小,但並非總是如此。UITableViewController偶爾調整TableView的大小

我附上了一些例子。兩者都有UITextField,這是當前的firstResponder。我拖動了兩個屏幕截圖以顯示滾動指示器。

左側的UITableViewController在鍵盤出現時調整了它的tableView,但右側的UITableViewController沒有。我究竟做錯了什麼?

編輯

感謝大家的幫助我在這個問題上。仍然沒有解決。他們都有UINavigationController作爲他們的parentViewController。右邊的是UINavigationControllerstopViewController,左邊的是topViewController。任何幫助,將不勝感激。




enter image description here enter image description here

+0

他們真的都是'UITableViewController'還是隻是一個'UITableView'裏面的'UIViewController'? – CrimsonChris

+0

這是一個棘手的問題,我之前在我的一個應用程序中看到過,並且認爲它與添加UITableView的方式有關。可能是左邊的那個在UINavigationController中被直接添加爲'UITableViewController',但是在右邊添加爲子視圖('UITableView')或者不在UINavigationController中? –

+0

我也得到了這個問題,也許你已經在表格視圖中包含了一些Outlets而不是在tableviewcell中 –

回答

2

所以,我想出了一個解決辦法:

- (void)setContentInsetWithTextField:(UITextField *)textField 
{ 
    CGFloat keyboardHeight = 216; 

    CGFloat movement = (textField.isFirstResponder ? keyboardHeight : -keyboardHeight); 

    UIEdgeInsets contentInset = self.tableView.contentInset; 
    contentInset.bottom = contentInset.bottom + movement; 
    self.tableView.contentInset = contentInset; 
} 

調用此方法在textFieldDidBeginEditingtextFieldDidEndEditing,它解決了問題!

+0

它不適合我... –

相關問題