Skip to content

Instantly share code, notes, and snippets.

@Mozilla9
Last active November 6, 2015 14:15
Show Gist options
  • Save Mozilla9/f87c04bda2e90fe2fbaf to your computer and use it in GitHub Desktop.
Save Mozilla9/f87c04bda2e90fe2fbaf to your computer and use it in GitHub Desktop.
@interface AsyncTable()

@property(nonatomic, strong) NSMutableArray* alphaKeys;
@property(nonatomic, assign) NSUInteger isDataLoading;

@end

@implementation AsyncTable    

-(void)refreshData {
        self.isDataLoading++;
        dispatch_async(_serialQueue, ^{
            NSMutableArray* tempAlphaKeys = <load data>;

            dispatch_async(dispatch_get_main_queue(), ^{
                self.isDataLoading--;
                
                if (self.isDataLoading == 0) {
                    [self.alphaKeys removeAllObjects];
                    [self.alphaKeys addObjectsFromArray:tempAlphaKeys];
                    
                    [table reloadData];
                }
            });
        });
}
...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.alphaKeys.count;
}
...
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment