tags:

views:

3753

answers:

1

Hi

I have a grouped table view with textfields in the tableview. For the keyboard to not hide the textfields, in the textFieldShouldBeginEditing, I am calling the scrollToRowAtIndexPath method and setting the scroll position of the row being edited to the top of the tableview.

The scrolling does happen, but as soon as the keyboard appears (ie as soon as the textFieldShouldBeginEditing returns YES), the table scrolls back to its original position and displays the first row of the first section on top. I am not calling reloadTable after making a call to scrollToRowAtIndexPath.

The problem occurs only for row 4 and 5 (bdate and zip) password2 works as expected.

This is the code I am using to scroll to a particular row

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 be going wrong? Any insight would help.

Thanks

+3  A: 

I suspect what is going on is that the table view is rubber banding back, just like a webview in Safari does when you run pass its bounds. The most likely reason for this is that when you pop up the keyboard it is on top of the table view, but the table view has not physically contracted, thus all the UITableViewCells fit within the partially obscured UITableView, and when some of them scroll off it rubber bands so they all are within it.

In order to test this try reducing the size of the list view so that you can see the whole thing when the keyboard is displayed, if the bug goes away you want to write code that dynamically changes the size as the keyboard animates in and out.

Louis Gerbarg
Hi. In the code that I specified, password2 is above bdate and zip fields and there are more cells after zip. zip is the last cell visible when the view first displays. Could that be the reason that other views are not drawn yet, leading to the table to bounce back? If not then why not move it up?
lostInTransit
It does not have to do with views not being drawn yet. The problem is that the tableview is larger than what you are displaying on screen. Just because a portion of it is being obscured by the keyboard does not mean it is not there, and view does the bounce based on how large it is.
Louis Gerbarg