Reputation: 12807
I sometimes reload table data and I need to redraw the table so that I see the data from the first row again. What I do now is the following:
NSIndexPath *ip = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:ip animated:NO scrollPosition:UITableViewScrollPositionTop ];
[self.tableView deselectRowAtIndexPath:ip animated:NO];
This is not ideal because there is an annoying flash when row 0 is selected and immediately deselected.
How can I fix this?
Upvotes: 2
Views: 3819
Reputation: 3716
If you have a header that is in view by default, and want to compensate if the action is called when the list is in motion use:
[tableview setContentOffset:CGPointMake(0.0, 0.0) animated:NO];
Short, simple, effective.
Upvotes: 2
Reputation: 163288
You can use UITableView
's scrollToRowAtIndexPath:atScrollPosition:animated:
method.
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
Upvotes: 13