gpt4 book ai didi

ios - 编辑单元格时更改 TableViewCell 的背景颜色

转载 作者:行者123 更新时间:2023-11-29 00:56:38 24 4
gpt4 key购买 nike

我有一个 tableView,其中包含一些具有黑色背景颜色的单元格。在点击导航栏中的编辑按钮时,我想将允许重新排序的区域的背景颜色更改为黑色而不是它显示的当前白色?

我可以使用下面的功能将编辑按钮更改为完成,但我不确定如何更改单元格的特定区域。我感觉到这是我改变它的地方,但我没有展示如何。

override func setEditing (editing:Bool, animated:Bool)
{
super.setEditing(editing,animated:animated)

if (self.editing) {

self.editButton.title = "Done"
self.navigationItem.setHidesBackButton(true, animated: true)

} else {

self.editButton.title = "Edit"
self.navigationItem.setHidesBackButton(false, animated: false)
}
}

这就是我所指的图像。

enter image description here

最佳答案

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

在这种“滑动删除”模式下, TableView 不显示任何插入、删除和重新排序控件。此方法使委托(delegate)有机会将应用程序的用户界面调整为编辑模式。

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

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

关于ios - 编辑单元格时更改 TableViewCell 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37568695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com