Hi,
I have a dynamic table view. Each cell have a stepper and UILabel. When I press the stepper control on a some cells and scroll, other cells are getting impacted and values of some cells that I filled gets remove too. I guess it's the consequence of using dequeueReusableCell from the cellForRowAt indexPath method. I found that i had to use the prepareForReuse method inside my UITableViewCell class, however I am still facing same issue. Any recommendation how to fix it.
I have a dynamic table view. Each cell have a stepper and UILabel. When I press the stepper control on a some cells and scroll, other cells are getting impacted and values of some cells that I filled gets remove too. I guess it's the consequence of using dequeueReusableCell from the cellForRowAt indexPath method. I found that i had to use the prepareForReuse method inside my UITableViewCell class, however I am still facing same issue. Any recommendation how to fix it.
Code Block class PlayerAssistContributionCell: UITableViewCell { @IBOutlet weak var playerName: UILabel! @IBOutlet weak var playerRating: UILabel! @IBOutlet weak var stepperLabel: UILabel! @IBOutlet weak var stepper: UIStepper! override func prepareForReuse() { super.prepareForReuse() stepperLabel.text?.removeAll() } @IBAction func StepperPressed(_ sender: UIStepper) { stepperLabel.text = Int(sender.value).description } }
Code Block extension PlayerAssistViewController: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return players.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let player = players[indexPath.row] guard let cell = tableView.dequeueReusableCell(withIdentifier: "PlayerAssistCell") as? PlayerAssistContributionCell else {return UITableViewCell()} let image = UIImage(data: ((player.image ?? defaultImage)!)) cell.imageView?.image = image?.resize(60, 60) cell.playerName.text = player.name cell.playerRating.text = "\(player.rating)" cell.cellLayer(with: cell) cell.StepperPressed(cell.stepper) return cell } }