在滑动时更改单元格的背景颜色以删除

时间:2013-09-23 12:08:32

标签: iphone ios uitableview

当用户滑动以获取删除按钮时,是否可以更改单元格的背景颜色。我已经搜索了很多但没有得到任何解决方案。

提前完成。

1 个答案:

答案 0 :(得分:4)

这将对您有所帮助:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  cell.backgroundColor = [UIColor redColor];
}

根据官方文档here,这种UITableViewDelegate方法是为这种工作量身定制的。

  

在“滑动删除”模式下,表格视图不显示任何内容   插入,删除和重新排序控件。这个方法给出了   委托调整应用程序用户界面的机会   编辑模式。

编辑 ::根据您要捕获事件的注释,当用户不删除单元格但滑动以结束编辑模式时。为此,我们有以下代表:

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
      UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
      cell.backgroundColor = originalColor;
}