I have a CollectionView with simple cells - a label and an image. Via AutoLayout I make sure the label is always on top of the image.
I use a 2-column layout, which produces the following view (debug mode / color blended layers):
In the CollectionViewController, when calling cellForItemAtIndexPath
, I use dequeueReusableCellWithReuseIdentifier
, which sets label text and imageview image to nil in the CollectionViewCell:
override func prepareForReuse() {
coverImage.image = nil
title.text = nil
collection = nil
}
However, when re-attaching the images, somehow AutoLayout stops working properly. When I scroll down, to cells that are initially outside the bounds of the view, the label is sometimes invisible and sometimes twice as big as it should be.
This is reproduceable and happens always on the same cells, however the underlying data is exactly the same as when the cells are layed out correctly (the label.text value is not nil or something with 2 lines).
I have tried various approaches to fixing this (including Auto Layout in UICollectionViewCell not working and UICollectionViewCell Auto Layout), however the problem is persisting.
I'm using/testing with iOS 9.3 and 8.1, and Xcode 7.3.1.