I have a grouped table view with text fields in a table view. To prevent the keyboard from hiding text fields, in textFieldShouldBeginEditing, I call the scrollToRowAtIndexPath method and set the scroll position of the row edited at the top of the table.
Scrolling occurs, but as soon as the keyboard appears (i.e. as soon as textFieldShouldBeginEditing returns YES), the table scrolls back to its original position and displays the first row of the first section at the top. I do not call reloadTable after calling scrollToRowAtIndexPath.
The problem only occurs for lines 4 and 5 (bdate and zip) password2 works as expected.
This is the code I use to go to a specific line
if(textField == password2){ indPath = [NSIndexPath indexPathForRow:3 inSection:0]; [self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; return YES; } else if(textField == bdate){ indPath = [NSIndexPath indexPathForRow:4 inSection:0]; [self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; return YES; } else if(textField == zip){ indPath = [NSIndexPath indexPathForRow:5 inSection:0]; [self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; return YES; }
Can someone please tell me what could go wrong? Any insight will help.
thanks
source share