滚动UITableView后保留单元格图像 [英] Preserve Cell Image After Scrolling UITableView

查看:47
本文介绍了滚动UITableView后保留单元格图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的UITableViewCell,它充当检查清单.当用户单击所选项目时,它会从红色变为绿色,表示已进行选择.但是,当用户向下滚动列表时,一旦回到顶部,图像就会变回其默认的红色值. /p>

在tableview回收单元格时,如何保存图像的状态?

谢谢

解决方案

听起来像您正在使用UITableViewCell来存储表数据的状态.这是错误的方法,因为单元已被重用.您应将状态保存在单独的数据存储"中.这可以只是保存在UITableViewController子类中的内存中的数组,也可以是诸如SQLite或Core Data之类的持久性数组.当表格视图要求您进入tableView:cellForRowAtIndexPath:时,此状态然后又转移回单元格.

I have a custom UITableViewCell which acts as a check list. As the user clicks on the selected item, it goes from red to green indicating a selection, however as the users scrolls further down the list, once they come back up to the top, the image has changed back to it's default red value.

How do I go about preserving the state of an image as the tableview recycles cells?

Thanks

解决方案

Sounds like you are using the UITableViewCells to store the state of your table data. This is the wrong approach because the cells are reused. You should keep state in an separate 'data store'. This can simply be an array you keep in memory in your UITableViewController subclass or something persistent like SQLite or Core Data. This state is then transferred back to the cell when the table view asks you to in tableView:cellForRowAtIndexPath:.

这篇关于滚动UITableView后保留单元格图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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