gpt4 book ai didi

ios - 在 iOS Swift 中更改单个 UITableView Cell 的颜色

转载 作者:可可西里 更新时间:2023-11-01 02:17:04 25 4
gpt4 key购买 nike

我希望能够更改单个 UITableView 单元格的颜色。在我的 tableView(editActionsForRowAtIndexPath) 中,我可以滑动单元格并选择一个按钮来更改背景颜色,但是当我将单元格滚动到屏幕外时,它会变回。我怎样才能让它保持颜色?谢谢

最佳答案

假设您的 tableView 中只有一个部分有很多行,您需要在 tableView:cellForRowAtIndexPath: 方法中执行此操作:

if (indexPath.row == coloredCellIndex) {
cell.backgroundColor = UIColor.RedColor()
} else {
cell.backgroundColor = UIColor.WhiteColor()
}

您需要在此函数之外的任何地方设置变量 coloredCellIndex,例如在 viewDidLoad 中

关于ios - 在 iOS Swift 中更改单个 UITableView Cell 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36830512/

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