Reputation: 18798
I'm using the following to raise a textfield inside a table cell above keyboard level. But this only works if I tap the textfield. If I focus the text field programmatically ,i.e., [textField becomeFirestResponder]
, it doesn't work. Edit: also textFieldShouldBeginEditing:
is being called but the code inside isn't performing as expected.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
CGPoint pointInTable = [textField.superview convertPoint:textField.frame.origin toView:_tableView];
CGPoint contentOffset = _tableView.contentOffset;
contentOffset.y = (pointInTable.y - textField.inputAccessoryView.frame.size.height);
[_tableView setContentOffset:contentOffset animated:YES];
}
return YES;
}
Upvotes: 0
Views: 99
Reputation: 420
You can use third party class TPKeyboardAvoidingTableView Which will automatically adjust and scroll TableView when keyboard get opens.
https://github.com/michaeltyson/TPKeyboardAvoiding
Upvotes: 0
Reputation: 3268
call [textField becomeFirstResponder]
and implement your keyboard avoiding code in textFieldDidBeginEditing
as it is called after editing has begun. On the other hand textFieldShouldBeginEditing
is called before beginning editing. You can properly obtain the keyboard height after editing has begun.
Upvotes: 0
Reputation: 1891
Try calling the [self textFieldShouldBeginEditing:textField]
after setting [textField becomeFirstResponder]
Upvotes: 1