@interface AsyncTable()
@property(nonatomic, strong) NSMutableArray* alphaKeys;
@property(nonatomic, strong) NSOperationQueue *serialQueue;
@end
@implementation AsyncTable
-(void)refreshData {
[self.serialQueue cancelAllOperations];
__block NSMutableArray* tempAlphaKeys;
NSBlockOperation *op = [[NSBlockOperation alloc] init];
op.completionBlock = ^{
if (!op.isCancelled) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.alphaKeys removeAllObjects];
[self.alphaKeys addObjectsFromArray:tempAlphaKeys];
[table reloadData];
});
}
};
[op addExecutionBlock:^{
tempAlphaKeys = <load data>;
}];
[self.serialQueue addoperation:op];
}
...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.alphaKeys.count;
}
...
@end
}
Created
November 6, 2015 14:44
-
-
Save Mozilla9/f8bfd3dd3af5288e1351 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment