在进入/退出编辑模式时重绘UITableViewCell [英] Redrawing UITableViewCell when entering/exiting edit mode

查看:123
本文介绍了在进入/退出编辑模式时重绘UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图,其中单元格是建立不同的取决于表是否正在编辑。具体来说,选择样式在编辑模式时为无,在不处于编辑模式时为蓝色。

I have a table view in which the cells are built differently depending on whether the table is editing or not. Specifically, the selection style is none when in edit mode and blue when not in edit mode.

当我从一个转换到另一个时,我注意到一些细胞不更新。一个快速的日志记录告诉我,即使细胞的外观变化相当大(例如附件视图被添加/删除正确),表视图不刷新选择风格(也不是那个文本)。

When I transition from one to the other, I noticed that some of the cells are not updated. A quick bit of logging tells me that even though the cells' appearance changes quite drastically (accessory views are added/removed correctly for example) the table view does not refresh the selection style (nor for that matter the text).

这里发生了什么事?当调用setEditing时,只有单元格的一些属性更新吗?大概只有那些具有特定方法允许分配单独视图样式(例如EditingAccessoryType)的方法?我想我会从EditingSelectionStyle中受益。

What is going on here? Are only some attributes of the cell updated when setEditing is called? Presumably only those with a specific method allowing allocation of a separate view style (for example the EditingAccessoryType)? I guess I would benefit from a EditingSelectionStyle.

我该如何解决?通过定制setEditing来更改每个单元格的selectionStyle?我甚至不知道我将如何迭代通过表视图来做到这一点。因为我使用了一些动画,reloadData不是一个选项。

How should I resolve it? By customizing setEditing to change the selectionStyle for each cell? I'm not even sure how I would iterate through the table view to do this. reloadData isn't an option because of some animation that I am using.

推荐答案

我发现自定义setEditing:

I found that customizing setEditing: to iterate through the visible cells and setting the selectionStyle for each to work ok.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{   
    [super setEditing:editing animated:animated];

    for (UITableViewCell *cell in [self.tableView visibleCells]) {
            NSIndexPath *path = [self.tableView indexPathForCell:cell];
            cell.selectionStyle = (self.editing && (path.row > 1 || path.section == 0)) ? UITableViewCellSelectionStyleNone : UITableViewCellSelectionStyleBlue;
    }
}

这篇关于在进入/退出编辑模式时重绘UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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