ios - 滚动后可重用的UITableViewCells更改

标签 ios

在我的UITableviewCell带有图片更新之前的一瞬间,它显示了重用单元格的图片。有谁知道解决这个问题的最佳做法?

我尝试了以下方法(但可能实现有误):

  • prepareForReuse。我尝试删除图片,但旧图像仍然短暂出现,但仍然闪烁(如果有人认为我拼错了,并且应该可以工作,我可以重写代码并发布)
  • 我尝试了几种缓存图像的方法:仍然不够快
  • 不重用单元格:出于多种原因,不是一个选项

  • 图像加载代码:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            static NSString *CellIdentifier = @"Cell";
    
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
            // Configure the cell...
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }
    
            UIImageView *pictureImageView = (UIImageView *)[cell viewWithTag:8];
            //Using AFNetworking
            [pictureImageView setImageWithURL:pictureURL];
    
    
            return cell;
        }
    

    最佳答案

    解决方案不是在单元格出现时尝试更改图像,而是在单元格消失之前隐藏旧图像,然后再使用。有一种方法可以做到这一点:

    -(void) tableView:(UITableView *)tableView didEndDisplayingCell:(BigPictureCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
       UIImageView *pictureImageView = (UIImageView *)[cell viewWithTag:8];
       pictureImageView.image = nil;
    
    }
    

    关于ios - 滚动后可重用的UITableViewCells更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21832061/

    相关文章:

    ios - 插页式广告坏了吗? iOS 8?

    ios - 什么情况下JSONSerialization.data(withJSONObject :) throw a catchable error?

    ios - Xcode-如何为不同的构建配置设置不同的包标识符?

    ios - 检查 UIbutton setImage 是否在 iOS 中被调用

    ios - 如何将汉堡菜单添加到 Xamarin iOS 项目?

    ios - 提交 EditingStyle 删除按钮不会显示

    Ios 应用程序未通过 FCM 控制台接收消息

    ios - 在 iOS Collection View 中的单元格顶部显示菜单 Controller

    ios - 如何从 Filtered UITableView 中删除一个项目,而不实际删除它?

    ios - 应用程序因 "improper IDFA"而被拒绝,而我没有使用任何广告服务