无需重新加载即可更新UITableViewCell [英] Update UITableViewCell without reload

查看:112
本文介绍了无需重新加载即可更新UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我的情况:



我有一个UITableView,其中每个单元格都有一些按钮。

在cellForRowAtIndexPath中我设置索引路径因此,当单击a按钮时,我知道单击了哪一行。

其中一个按钮是删除按钮,按下时我删除了支持数据并从表中删除了该行。 />



我遇到的问题是,在删除行之后,其他行的indexPath不正确,因为其他行尚未重绘。我可以找到重绘表的唯一方法是调用重新加载,但这会弄乱动画。

我认为这种问题必须先解决。有没有人对如何解决这个问题有任何建议?如果有更好的方法,我可以改变我设计按钮的方式。

解决方案

它是最好不要使用按钮存储indexPath。在按钮操作处理程序(它是您的单元子类或viewController中的方法)中,您可以识别单元格,然后使用 -indexPathForCell:确定indexPath。 / p>

So here's my situation:

I have a UITableView where each cell has some buttons.
In the cellForRowAtIndexPath I set the indexpath of the row so when the a button is clicked I know what row was clicked.
One of the buttons is a delete button and when pressed I remove the backing data and delete the row from the table.

The problem I'm having is that after I delete a row the indexPath's of the other rows are incorrect as the other rows have not been redrawn. The only way I can find to redraw the table is to call reload but this messes up the animation.
I figure this kind of problem must have been addressed before. Does anyone have any suggestions on how to get around this? I'm ok with changing the way I've designed my buttons to work if there is a better way.

解决方案

It is better not to store the indexPath with the buttons. In the button action handler (which is either a method in your cell subclass or in your viewController) you could identify the cell, and subsequently determine the indexPath using -indexPathForCell:.

这篇关于无需重新加载即可更新UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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