views:

24

answers:

2

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?

+2  A: 

You can use UITableView's scrollToRowAtIndexPath:atScrollPosition:animated: method.

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
Jacob Relkin
A: 

You can set contentoffset of tableview to (0.,0.).

Pragnesh Dixit