7

I have absolutely zero idea why this is happening, but for whatever reason a collection view I am using is infinitely looping the [UICollectionViewData layoutAttributesForElementsInRect:] method.

The collection view is inside of my custom navigation bar. In one scenario where I use this custom navigation bar, everything works as expected. In another scenario, it loops infinitely.

  • I have experimented with not setting the data source or delegate on the collectionView.
  • I have tried setting the data source and delegate, but returning 0 for itemsInSection.
  • I am using auto layout as in the working situation, and I am initialising the custom navigation bar as in the working situation.

In regard to posting code, I am not sure exactly what to post. The infinite loop begins after [UIWindow makeKeyAndVisible] is called. This method never returns. It was only after time profiling that I discovered that it was this [UICollectionViewData layoutAttributesForElementsInRect:] that was causing the problem.

codrut
  • 810
  • 10
  • 19
Infinity James
  • 4,376
  • 4
  • 19
  • 34

2 Answers2

13

I had the same infinite loop problem inside [UICollectionViewData layoutAttributesForElementsInRect:] when i was manually updating contentOffset to collectionView with no elements (i.e. when numberOfItemsInSection was 0).

1

I had a problem with the heights of different collection views in a table view so i followed this UICollectionView inside a UITableViewCell — dynamic height?. But i mistakenly commented out the [self.collectionView layoutIfNeeded]; because i had thought it would improve scrolling performance. I uncommented it and it worked again! Not sure why it works though

Zhong Huiwen
  • 529
  • 7
  • 8