滚动UITableView时停止图像消失 [英] Stop Images Disappearing when scrolling UITableView

查看:68
本文介绍了滚动UITableView时停止图像消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UI表格视图控制器。每个单元从我的Web服务器加载图像。
如果我滚动TableView以便某个特定的单元格从视图中滚动出来,然后再次向后滚动,则该单元格的图像消失了,我必须等待它重新加载。



我想这是iphone中内置的一些性能/内存管理功能吗?



我如何停止这种行为?

解决方案

我相信表视图中的单元格已回收。



将图像缓存在内存中并分配

我不知道这是否是最佳实践,但我认为您可以使用 NSArray UIImage NSDictionary 并首先加载到其中,然后将引用分配给



更新



有一些代码此处 s NSMutableDictionary 缓存


I have a UI Table View Controller. Each Cell Loads an image from my webserver. If I scroll the TableView so that a particular cell scrolls out of view and then scroll back again the image for that cell has vanished and I have to wait for it to reload.

I'm guessing this is some performance/ memory management thing build into iphone?

How can I stop this behaviour?

解决方案

I believe the cells in the tableview are recycled.

cache the images in memory and assign from your cache rather than loading the images directly into the tableview

I don't know if this is best practice or not but I think you could use an NSArray or NSDictionary of UIImage and load into there first and just assign references to the objects in the array.

Update

There is some code here which uses an NSMutableDictionary for the cache

这篇关于滚动UITableView时停止图像消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆