Problems changing UITableView insets when keyboard its showed

96 Views Asked by At

Here is the deal, I have a UITableView, and I add a custom cells with different elements like UITextFields and others that have a UITextView. When a textfield is clicked and the keyboard appears, I change the contentInset of my UITableView so the both, the keyboard and the textfield will be visible for the user.

The problem is that it seems to not work when I do this when the user click a UITextView! I try to change the contentinset but nothing happens. Here are some snipped codes.

PD: Im doing all the "register for remote not when the keyboard appears" thing. I will not add it here.

- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];

self.keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

_uploadTableView.contentInset =  UIEdgeInsetsMake(0, 0, _keyboardSize.height, 0); }


- (void)keyboardWillBeHidden:(NSNotification*)aNotification {
_uploadTableView.contentInset =  UIEdgeInsetsMake(0, 0, 0, 0); }
1

There are 1 best solutions below

0
On

Along with changing the content insets, You need to scroll to row in which UITextView is present.

In keyboardWasShown

_uploadTableView.contentInset =  UIEdgeInsetsMake(0, 0, _keyboardSize.height, 0);

NSIndexPath *indexPathOfRowContainingTextView ;//you can get the Indexpath from indexPathForCell method of UITableView
[_uploadTableView scrollToRowAtIndexPath:indexPathOfRowContainingTextView atScrollPosition:UITableViewScrollPositionTop animated:YES];

In keyboardWillBeHidden

_uploadTableView.contentInset =  UIEdgeInsetsMake(0, 0, 0, 0);