大佬教程收集整理的这篇文章主要介绍了ios – UITableView使重新加载旧图像的单元格出列,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (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,^{ //This is what you will load lazily 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,accImageView.image.size.width,92)]; cell.accessoryView = accImageView; //[cell setNeedsLayout];//not needed }); }); [cell.textLabel setText:RSSItem.title]; [cell.detailTextLabel setText:RSSItem.sumMary]; return cell;}
dispatch_async(dispatch_get_main_queue(),^{ UITableViewCell *updateCell = [tableView cellForRowATindexPath:indexPath]; if (updateCell != nil) { // update image in `updateCell` } });@H_673_2@请注意,这个UITableView方法
cellForRowAtIndexPath
不应该与UITableViewDatasource方法tableView:cellForRowAtIndexPath:
混淆.前者只是检查单元格是否可见,如果是,则返回指向它的指针.显然,后者是您在问题中引用的方法,用于创建和配置表视图单元格.
@H_673_2@另请注意,您使用NSIndexPath检查单元格是否仍然可见的这个想法假设在中间时间内表格视图中可能没有插入其他行.这通常不是一个有效的假设,因此您甚至可能必须返回基础模型并重新计算此单元格的indexPath,然后再继续上述逻辑以查看该单元格是否仍然可见.以上是大佬教程为你收集整理的ios – UITableView使重新加载旧图像的单元格出列全部内容,希望文章能够帮你解决ios – UITableView使重新加载旧图像的单元格出列所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。