UIRefreshControl not working when called prorgammatically

Yury Pogrebnyak picture Yury Pogrebnyak · May 23, 2013 · Viewed 11.3k times · Source

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;

Answer

Valent Richie picture Valent Richie · May 23, 2013

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.