Sunday, 18 August 2013

Scrolling a table view with text fields when "Next" return button in keyboard

Scrolling a table view with text fields when "Next" return button in keyboard

I have a grouped table view with custom cells, and these cells have a
UITextField. I've set the returnKeyType of the text fields to be
UIReturnKeyNext (except for the last row), and I've implemented their
textFieldShouldReturn: method this way:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
id firstResponderCell = textField.superview.superview ;
NSInteger firstResponderRow = [self.tableView
indexPathForCell:firstResponderCell].row ;
NSIndexPath* nextCellIndexPath = [NSIndexPath
indexPathForRow:firstResponderRow+1 inSection:0] ;
CustomCell* nextCell = (CustomCell*)[self.tableView
cellForRowAtIndexPath:nextCellIndexPath] ;
if (nextCell) {
[nextCell.cellTextField becomeFirstResponder] ;
}
else
[textField resignFirstResponder] ;
return YES ;
}
But I'm not able to scroll the table view content in order to make the
current active text field visible above the keyboard. I successfully
managed this when I did not implement the "Next" button functionality in
keyboard and keyboard was just hidden when "Enter" button was tapped, and
then the keyboard was again shown when another text field was tapped,
since I'm listening for UIKeyboardDidShowNotification and
UIKeyboardDidHideNotification. But now that I want a "Next" button in
keyboard and keyboard is not being hidden when tapping the button, I don´t
know how to scroll to the active text field properly.
Thanks in advance

No comments:

Post a Comment