I know this has been asked many times, but please bear with me as I tried for several days to find a solution.
I have an rss parser, a tableview with: text, details and images set in AccessoryDisclosureIndicator.view.
Images are uploaded using the simple async GCD: fast scrolling for hundreds of results. NO lag, NO errors if I have a good connection.
The problem is that for a split second - they flicker when loading, because the cell is being reused. In addition, if the connection is poor, it sometimes leaves a hinged image, but the text / detail is correct, only the image is out of date ... So let me repeat, the text / details are updated perfectly and NEVER make a mistake, just the image sometimes rarely gets queued incorrectly with poor connections / grip scrolling forward and backward.
My question is, can someone help me cache / tag cell.accs.views? I tried installing cellIDs but had problems with my implementation. My code below works fine if the connection never slows down, just a little flicker when the cell reloads, which I don't mind.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[cell.textLabel setNumberOfLines:3];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
[cell.detailTextLabel setNumberOfLines:3];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12.0];
cell.detailTextLabel.textColor = [UIColor blackColor];
}
RSSItem * rssItem = (RSSItem *)(_rssParser.rssItems)[indexPath.row];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:rssItem.imageURL]];
dispatch_sync(dispatch_get_main_queue(), ^{
UIImageView *accImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:data ]];
[accImageView setFrame:CGRectMake(0, 0, accImageView.image.size.width, 92)];
cell.accessoryView = accImageView;
});
});
[cell.textLabel setText:rssItem.title];
[cell.detailTextLabel setText:rssItem.summary];
return cell;}
Joshp source
share