- [UITableView scrollToRowAtIndexPath:] scrolls, but returns to the 1st row

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

+4
source share
2 answers

I suspect what happens is that the table view is a rubber band back, just like Safari's webview when you skip your borders. The most likely reason for this is that when you open the keyboard, it is on top of the table view, but the table view is not physically reduced, so all UITableViewCells fit into the partially hidden UITableView, and when some of them scroll, these are rubber bands so that they all in him.

To check this, try reducing the size of the list view so that you can see all this when the keyboard is displayed, if the error disappears, you want to write code that dynamically resizes as the keyboard animates and out.

+5
source
 //For iOS 7 [self.TableView reloadData]; NSIndexPath *indexPat = [NSIndexPath indexPathForRow:1 inSection:1]; [self.TableView scrollToRowAtIndexPath:indexPat atScrollPosition:UITableViewScrollPositionTop animated:YES]; 
0
source

All Articles