Fyodor Volchyok
Fyodor Volchyok

Reputation: 5673

UICollectionView doesn't render cells

In my view I have a UITableView which contains cells with horizontal UICollectionView inside. The problem is that sometimes UICollectionViewCells are not rendered on device/simulator. At the same time I can see those cells in the View Hierarchy Debugger:

What I see in the View Hierarchy Debugger: enter image description here

What I see on a device: enter image description here

As you can see, cells (with images) exist and have correct frames and content (proved by the View Hierarchy Debugger). Nevertheless they are not rendered on device/simulator for some reason. What could be the cause of that and how could I fix it?

UPD: another example with "3D" view and bug on one cell, but not on the other

device screenshot: enter image description here

view hierarchy debugger: enter image description here

Upvotes: 10

Views: 995

Answers (1)

Fyodor Volchyok
Fyodor Volchyok

Reputation: 5673

It turned out that my particular problem is related to UICollectionView assertion error on stale data because sometimes mentioned crash happens. Playing around [collectionViewLayout invalidateLayout] I finally fixed this.

Just to record what was NOT the cause (and what you should check if faced with the same problem):

  1. check if you update views in the main thread only
  2. check if all autolayout constants are set correctly and don't conflict
  3. check that your custom views' intrinsic content sizes are calculated correctly

If none of the above is the cause of issue try invalidateLayout somewhere around reloadData or inside of layoutSubviews or similar method.

Upvotes: 1

Related Questions