简体   繁体   中英

How to access cell properties outside of declaration function?

I have created a tableView that returns a cell. I want to be able to change the cell properties outside of the dequeReusableCells function. I have tried this:

let index = IndexPath(row: 1, section: 0)
let refCell = tableView.cellForRow(at: index)
refCell?.textLabel?.textColor = .white

but it only changes the textLabel color to white for the second cell. How can I do this for all cells (other than using a for loop)?

for changing all UITableViewCells you should create

fileprivate var myColor: UIColor = .black

inside UIViewController

then inside cellForRowAt indexPath

cell.textLabel?.textColor = self.myColor

then whenever you want to change this color just do

self.myColor = .white
self.myTableView.reloadData()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM