UITableViewCellAccessory Disappears When Scrolled Off Screen

前端 未结 5 522
独厮守ぢ
独厮守ぢ 2021-01-22 12:42

I have a UITableView filled with objects. In the didSelectRowAtIndexPath method i have a UITableViewCellAccessoryCheckmark appear when the row is selected and disappea

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 13:36

    Your cells get re-used as you scroll through the data (that's what the dequeueReusableCellWithIdentifier does). Your cell that got a checkmark in didSelectRowAtIndexPath gets recycled for a different row and no longer has any connection to the checked row.

    You need to set/unset the accessory view in cellForRowAtIndexPath so when the checked rows scroll back into view, they get checked appropriately.

提交回复
热议问题