本文介绍了更改要删除的单元格的背景颜色以进行删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to change background color of cell when user swipes it to get the delete button. I have searched a lot for it but did not get any solution.

先感谢

推荐答案

这将为您提供帮助:

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

根据官方文档此处,此 UITableViewDelegate 方法是针对此类工作量身定制的.

According to official documentation here, this UITableViewDelegate method is tailor made for such kind of work.

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

EDIT:: According to the comment you want to capture the event when user does not delete the cell but swipe to end the editing mode. For this, we have the following delegate:

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

这篇关于更改要删除的单元格的背景颜色以进行删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 22:54