Matt Douhan
Matt Douhan

Reputation: 2113

Why does my UITableViewController not refresh when I use UIRefreshControl?

I have a UITableViewController that implements the UIRefreshControl to refresh the data from the server, from the debugs I can see that the refresh method is called and the new correct data is downloaded but my UITableViewController is not reflecting this.

if I close the UITableViewController and open it again the correct data is shown

my refresh code looks like this

- (void)viewDidLoad {
    [super viewDidLoad];

    UIRefreshControl *refresh = [[UIRefreshControl alloc] init];

    refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];

    [refresh addTarget:self action:@selector(updateData)

    forControlEvents:UIControlEventValueChanged];

    self.refreshControl = refresh;
}

- (void) updateData {

    [ShopifyWebServices fetchAllProductsInCollection:shopifyCollectionTitle];

    [self performSelector:@selector(stopRefresh) withObject:nil afterDelay:5];
}

- (void)stopRefresh {

    [self.refreshControl endRefreshing];

}

Upvotes: 0

Views: 108

Answers (1)

jrturton
jrturton

Reputation: 119242

You are responsible for reloading your table view once you have the new data. The refresh control doesn't do anything other than tell you it's been triggered.

I'd expect some sort of delegate method or completion block after fetchAllProductsInCollection, and that is where you should be calling endRefreshing and reloading your table data.

Upvotes: 2

Related Questions