我创建了一个返回单元格的 tableView。我希望能够在 dequeReusableCells 函数之外更改单元格属性。我试过这个:
let index = IndexPath(row: 1, section: 0)
let refCell = tableView.cellForRow(at: index)
refCell?.textLabel?.textColor = .white
但它只将第二个单元格的 textLabel 颜色更改为白色。我怎样才能对所有单元格执行此操作(除了使用 for 循环)?
最佳答案
为了改变你应该创建的所有 UITableViewCells
fileprivate var myColor: UIColor = .black
在 UIViewController
中
然后在 cellForRowAt indexPath
cell.textLabel?.textColor = self.myColor
然后每当你想改变这个颜色就做
self.myColor = .white
self.myTableView.reloadData()
关于ios - 如何在声明函数之外访问单元格属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44094877/