UITableView sets the selected row to update control

I would like to set selected row to UITableView in refresh control . I do this because I have update control at the top of my UITableView , and when I load data (and they haven’t actually called it by pulling it), I would like the activity indicator view be visible (this is part of refresh control )

Right now, what I'm doing is setting the refresh control to a “refreshing state” (it has a spinning activity indicator).

 [self.refreshControl beginRefreshing]; 

This works fine, but the only problem is that they do not see it until they pull it out due to the default value in row 1 (index 0), so it is hidden.

Note: There are 0 elements in the UITableView (and always will be).

For example, if I go:

 [self.tableView selectRowAtIndexPath:0 animated:YES scrollPosition:UITableViewScrollPositionTop]; 

It will set the position of the selected item to the first line, but I want it to display the update control, so it’s probably possible:

 [self.tableView selectRowAtIndexPath:-1 animated:YES scrollPosition:UITableViewScrollPositionTop]; 

will work (like 1 index below the first element), but of course it will not be a compiler.

+4
source share
1 answer

Since UITableView is a subclass of UIScrollView, you can show the update controller above the first row by setting tableView contentOffset. For example, if your update control height is 100, you can animate the update control in the view.

 [self.tableView setContentOffset:CGPointMake(0, -100) animated:YES]; 

Or just show it without animation or implement your own animation:

 self.tableView.contentOffest = CGPointMake(0, -100); 

Then you can set it back to 0 after the update is complete and you want to hide the control.

Documentation link here

+2
source

All Articles