Yury Pogrebnyak Yury Pogrebnyak - 12 days ago 6
iOS Question

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;

Answer

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.

Comments