I am trying to utilize dispatch mechanism to get the contents on background, and update the tableview once gets it, however, such mechanism works, but once reloading, the tableviewcell is unclickable. When I remove [self._tableView reloadData], it is being clickable. Below is my code. Any suggestions?
NSString *const cellIdentifier = @"AutoFill";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSString *te = [tableData objectAtIndex:indexPath.row];
NSArray *a = [te componentsSeparatedByString:@" "];
dispatch_sync(dispatch_get_main_queue(), ^{
cell.accessoryType = UITableViewCellAccessoryNone;
[self._tableView reloadData];
});
});
return cell;
There is no need to access that array in the background – you are just adding complexity for the sake of adding complexity, which is never useful.
I think you get the point…
You should not be calling
reloadDatawhen you provide a row it will be displayed in the tableViewNote if you did the normal thing and didn’t fetch the data in the background this would not even be an issue you had to worry about
Update
Your code accesses an array in the background – does nothing useful with it and then calls back to the main thread to set a property that is not even determined by the result of the work in the background thread. What are you actually trying to achieve?