Reusing cell doesn't work well - TableView

前端 未结 6 1865
余生分开走
余生分开走 2021-01-27 12:35

I have a problem about my cell\'s button. In my tableView each row is composed by: an image, some labels and a button. The button has a checkmark image. When it is clicked, the

6条回答
  •  隐瞒了意图╮
    2021-01-27 13:05

    From the information in your post, this looks like a cell reuse issue. The problem is that the tableView reuses the cells rather than creating new ones, to maintain performance. If you haven't reset the cell's state, the reused cell will be remain configured in the old state.

    For a quick fix, you can implement the prepareForReuse method on UITableViewCell.

    However, you'll need to store which cell is 'checked' in your view controller if you want the checkbox to be selected after scrolling the tableView. You can store this yourself, or use the tableView's didSelectRowAtIndexPath method.

提交回复
热议问题