Button state activates on wrong cells

前端 未结 3 423
一生所求
一生所求 2021-01-16 04:47

I added button into cell-s and added action so if user touches it then the state is \"Dislike\" and if user touches again the state is \"Like\". However, the state applies t

3条回答
  •  时光取名叫无心
    2021-01-16 05:29

    This is caused by reusing previous cells when scrolling and is the base mechanism of a table view.

    You need to reset the state of your button on every call to cellForRowAtIndexPath.

    Between let cell = ... and cell.starButton.addTarget you need to perform something like cell.starButton.deselect(), or .select(), based on the index path you're working on.

提交回复
热议问题