当用户滑动单元格以获得删除按钮时,是否可以更改单元格的背景颜色。我已经搜索了很多但没有得到任何解决方案。
提前致谢。
最佳答案
这会对您有所帮助:
- (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/