[iOS] – Prevent wrong loading image inside of TableViewCell when scrolling. ?>

[iOS] – Prevent wrong loading image inside of TableViewCell when scrolling.

My current project require a screen which contain a list view on it. Each item of that list will show the information of a drug store and there is a image on it too. It’s really simple. In iOS we just need to drag a UITableView to the controller, add a UITableViewCell to it, create a Cell class for that cell and finally inside the cellForRowAtIndexPath we just fill data for that cell. 

Okay, everything work well but… until you scroll the list to the end and scroll to top again… the problem is the image was load in wrong cell.

Hmmm… what’s happen here! I do some small test to make sure the data which I pass to the cell is correct. So I show the indexPath, the image URL… on the cell and than everything is correct. Okay, so problem is just for the image.

There are no correct answer for this problem is the result after I made many search on internet and SO. It’s look like somehow Apple will caching the image for re-use purpose and it’s impact to the cell itself.

I found that it’s only happen when there is a item which I don’t set the image for it.

At you can see, if the noti.image is nill then I don’t set the image for the _storeImage that cause problem. So I change my code to:

OMG, it’s work now! I really cannot explain what’s wrong here but at least I can solved my problem.

Leave a Reply

Your email address will not be published. Required fields are marked *