Reputation: 2652
I have a UICollectionview with 4 UIImageviews inside. These are there for showing specific icons on the cells. Unfortunately when I have a cell that populates all 4 image views with images it works correctly. But when a cell should only display less than 4 items, it sometimes ( so not always ) shows additional icons. It seems to be from other (previous) cells. Like its not recycled properly.
Here is my code. I have an outlet that stores all imageviews inside.
@IBOutlet var savings: [UIImageView]!
Next I have a method inside my Cell Viewcontroller that populates according to the given array of icon names.
func setPropositions(propositions: [SupplierProposition])
{
for (index, item) in propositions.enumerate() {
if index < 4 {
savings[index].image = nil
savings[index].setNeedsDisplay()
if let image = UIImage(named: item.iconName!) {
savings[index].image = image
} else {
savings[index].image = nil
}
}
}
}
as you see I tried everything to make sure the imageviews are empty before rendered, but it doesn't work. Anyone that know what I might be doing wrong?
Upvotes: 0
Views: 471
Reputation: 535402
Like its not recycled properly
No. It's like you are not recycling it properly. It is your job, in cellForItemAtIndexPath:
, to completely configure this cell. This cell may have been used already, so it may already have image views in it that you placed there earlier; and if the cell for this index path is supposed to have fewer image views, it is your job to remove the ones you don't want.
Upvotes: 1