0

I have enabled refreshing in my tableview.

I have registered a Action parameter and i want stop the activity indicator from spinning once the table has stopped reloaded. When i researched on this, i learned that i should add a block and execute the success clause if the table has refreshed and if not display an error if not.

How can i add a block that suites my needs.

- (IBAction)refresh:(UIRefreshControl *)sender {

        [self.tableView reloadData];

        [sender endRefreshing];

}
Nilesh Patel
  • 6,318
  • 1
  • 26
  • 40
Illep
  • 16,375
  • 46
  • 171
  • 302
  • I guess this helps you: http://stackoverflow.com/questions/4163579/how-to-detect-the-end-of-loading-of-uitableview – kabarga Apr 27 '15 at 11:07

1 Answers1

0

Ohh.. Ok got it.. You are using refreshControl.. So whenever you are refreshing table content, your method should be asynchronous, so that your UI doesn't blocked. And whenever you are done, you should reload tableview on main queue.

 - (IBAction)refresh:(id)sender {
    __weak UIRefreshControl *refreshControl = (UIRefreshControl *)sender;
    if(refreshControl.refreshing) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            /* (... refresh code ...) */
            dispatch_sync(dispatch_get_main_queue(), ^{
                [refreshControl endRefreshing];
                //reload the table here, too
            });
        });
    }
}
iCoder
  • 1,298
  • 1
  • 9
  • 25
  • I stop the activity indicator by `[sender endRefreshing];`. So how am i going to stop it according to your code ? – Illep Apr 27 '15 at 14:30
  • Have you added activity indicator on each of the cell of your tableview ?? – iCoder Apr 28 '15 at 10:14
  • No. I enabled `UIRefreshControl `. I didn't add any activity indicator – Illep Apr 29 '15 at 04:06
  • I thought you were just using normal Tableview with activityIndicator.. Please find updated answer.. It might help you !! – iCoder Apr 29 '15 at 04:20