Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIRefreshControl not working when called prorgammatically

I have a UIRefreshControl in my ViewController and a method refreshView to handle "pull to refresh" event. It works perfectly when actually pulling, but when I call [refresh beginRefreshing] in code, it just shows refresh animation but doesn't call the refreshView method.

Here's code for initializing refresh control in viewDidload:

UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[refresh addTarget:self
            action:@selector(refreshView:)
  forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;
like image 245
Yury Pogrebnyak Avatar asked May 23 '13 15:05

Yury Pogrebnyak


1 Answers

Based on my understanding on the documentation: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIRefreshControl_class/Reference/Reference.html

Tells the control that a refresh operation was started programmatically. ... Call this method when an external event source triggers a programmatic refresh of your table.

I think it is not used to start a refresh operation, rather it is just for updating the refresh control status that it is currently refreshing, in which it will make the refresh control spinning. The purpose will be to avoid the user pulling the table view and trigger the refresh operation again while it is still refreshing.

So you should call the refreshView: method by yourself.

like image 180
Valent Richie Avatar answered Oct 31 '22 19:10

Valent Richie