我在其中细胞依赖于该表无论是编辑还是不建一个不同的表视图。 具体地,选择的风格是没有在编辑模式下,蓝色的时候不是在编辑模式。
当我从一个到另一个过渡,我注意到,一些细胞不被更新。 记录的快速一点告诉我,即使细胞的外观变化非常显着(附件视图添加/例如正确删除)表视图不刷新选择风格(也没有为此事文本)。
这里发生了什么? 只更新某些单元格的属性时setEditing叫? 据推测只有那些与特定的方法允许的单独视图式样(例如EditingAccessoryType)配置? 我想我会从EditingSelectionStyle受益。
我应该如何解决呢? 通过定制setEditing改变每个单元的selectionStyle? 我甚至不知道我怎么会遍历表视图做到这一点。 reloadData是不是因为一些动画,我使用的一个选项。
我发现定制setEditing:通过可见单元格进行迭代,并设置selectionStyle每个工作确定。
- (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;
}
}
如果你看的UITableViewDelegate文档,你会看到,有五种方法可以自定义编辑行为。 也有方法
- (BOOL)tableView:(UITableView *)tableView
canEditRowAtIndexPath:(NSIndexPath *)indexPath
在UITableViewDataSource文件 ,将在每个单元你进入编辑模式之前被调用。 同样是真正的
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
将调用为可编辑的所有单元格。 如果你想改变的方式,细胞看看你能做到这一点在这两种。 (未采取canEditRow..
假定所有行进行编辑。)
还要注意,可能还有其他的方式进入编辑模式,如刷卡的单元格,在这种情况下,
- (void)tableView:(UITableView *)tableView
willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
将被调用为您刷卡的细胞:
当进入此“滑动删除”编辑模式,表视图发送的tableView:willBeginEditingRowAtIndexPath:消息发送到委托,以允许其调整它的用户界面。
这适用于雨燕2.3,只是覆盖setEditing方法在您的自定义单元格的子类:
class MyCell: UITableViewCell {
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
//Place your code here...
}
}