Saturday, November 7, 2026
HomeiOS Developmentios - Collection of UITableViewCell Adjustments when Scroll down in Swift

ios – Collection of UITableViewCell Adjustments when Scroll down in Swift

[ad_1]

I’m utilizing a UITableView and what I’m doing is I’m altering the colour of the cell once I faucet on the cell utilizing didSelectRow perform of UITableView at cellForRowAt. The factor which is bothering me is once I scroll down or scroll up, these cells whom I modified the colour earlier than have been modified to different cells. Right here is my code:

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

     let cell = myTableView.dequeueReusableCell(withIdentifier: "TasksTableViewCell") as! TasksTableViewCell

     cell.backView.backgroundColor = .white

  return cell
} 

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

  let cell = myTableView.cellForRow(at: indexPath) as! TasksTableViewCell

  cell.backView.backgroundColor = UIColor(named: "primaryViewColor")
} 

Does anybody is aware of why this occurs? Does anybody has an answer that when solely these cells modifications coloration whom I faucet on, and once I scroll down or transfer up solely these cells have the opposite coloration?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments