Stop Images Disappearing when scrolling UITableVie

2019-05-11 16:45发布

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?

1条回答
爷的心禁止访问
2楼-- · 2019-05-11 16:56

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

查看更多
登录 后发表回答