iOS: CellForRowAtIndexPath cells are getting mixed up

前端 未结 3 1638
走了就别回头了
走了就别回头了 2021-01-06 02:53

Going to start off by saying I\'ve seen these questions:

iOS: UITableView mixes up data when scrolling too fast

(custom) UITableViewCell's mixing up afte

3条回答
  •  -上瘾入骨i
    2021-01-06 03:09

    There are a couple of ways to deal with this cell reuse problem (and that is what the problem is), and the way you're doing it now is ok. The problem is that when you scroll down and back up again, the cell that's returned for section 0 could be a cell that was previously used for section 1, so it will have any subviews you put in there.

    Another way to handle this, is to create two different prototype cells in the storyboard, and return the one with a simple label for section 0, and return the other one, with any subviews added in IB, for section 1. This way, you will always get the correct type of cell for each section without having to remove any subviews -- you only need to re-populate the cell with the correct data.

提交回复
热议问题