Set up refreshControl on tableView

suggest change

On iOS 10 and later, assign tableView.refreshControl instead of only adding the control as a subview. endRefreshing stays on the main queue. The sleep stands in for the reload.

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(pullToRefresh:) forControlEvents:UIControlEventValueChanged];
self.scrollView.alwaysBounceVertical = YES;
[self.scrollView addSubview:refreshControl];
- (void)pullToRefresh:(UIRefreshControl*) sender{
    //Do work off the main thread
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // Simulate network traffic (sleep for 2 seconds)
        [NSThread sleepForTimeInterval:2];
        //Update data
        //Call complete on the main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            //Update network activity UI
            NSLog(@"COMPLETE");
            [sender endRefreshing];
        });
    });
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents