Reusing iOS uitableview uitableviewcell has old data

We all know that a cell in a uitableview can be restored, but I see some strange results. I create a custom cell, each cell has 4 columns, each column has an image so the format is as follows: | IMG | IMG | IMG | IMG | after returning the cell, I configure each cell, the example will configure the first column for image 1, then the second column for another image

now it’s just assumed that I can only display two rows at a time in a table:

|a0|a1|a2 |a3 |
|b4|b5|b6 |b7 |
------cell c not visible to user------
|c8|c9|c10|c11|

as the user scrolls down, the column “a” (a0-a3) above becomes invisible, and as far as I know that the cell becomes invisible, it will be reused for column c

the above example works fine if I can completely occupy each cell / row, i.e. I have only 12 images.

but if I say 10 images (the last line will be filled only 2, and the other two are empty, for example:

|a0|a1|a2 |a3 |
|b4|b5|b6 |b7 |
------row/cell 'c' not visible to user------
|c8|c9|empty|empty|

however, the problem occurs when I look up to see cell / row 'c' I have the following picture:

|a0|a1|a2 |a3 |
------row/cell 'a' not visible to user------
|b4|b5|b6 |b7 |
|c8|c9|a2|a3|

note that the row / cell from the last two columns should be empty, but instead displays a2 and a3

how can i fix this? I am thinking of a manual way to do this, that is, by checking whether to delete unnecessary views, etc. when reused, but can be more difficult is there a more systematic way to make it easier and cleaner?

Is there a way we could ask the returned cell to forget its contents, or should I do it myself?

+5
2

. Override prepareForReuse tableview .

+7

" ". , UITableViewCell , . , reset/, .

UITableViewCell prepareForReuse reset , , .

UIImageView image nil .

+9

All Articles