iphone - 滑动删除时更改单元格的背景颜色

标签 iphone ios uitableview

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

提前致谢。

最佳答案

这会对您有所帮助:

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

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

In this "swipe to delete" mode the table view does not display any insertion, deletion, and reordering controls. This method gives the delegate an opportunity to adjust the application's user interface to editing mode.

编辑::根据评论,您要捕获当用户不删除单元格而是滑动结束编辑模式时的事件。为此,我们有以下委托(delegate):

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

关于iphone - 滑动删除时更改单元格的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18958883/

相关文章:

iphone - 图像比较在 ios 模拟器中不起作用

iphone - AVAsset 和 AVAssetTrack - IOS 4.0 中的跟踪管理

iphone - Objective-C 中的长轮询

ios - 由于无法识别电影文件格式,无法打开视频文件

ios - 如何检查UIViewController类是作为SDK的一部分定义还是由用户定义?

ios - FaSTLane 发送 : promote for review

ios - 可以从哪个 View Controller 检查 segue 然后执行某些操作吗?

swift - 一次只检索 5 个用户 :Firebase [like Instagram]

ios - 在 iOS 中我可以使用什么来代替 NSBitmapImageRep? (水波纹示例)

ios - AutoLayout uitableviewcell in landscape and on iPad calculating height based on portrait iPhone