Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite Loop of layoutAttributesForElementsInRect

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.

like image 689
Infinity James Avatar asked Jun 05 '14 16:06

Infinity James


1 Answers

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).

like image 65
Andrew Rozdolsky Avatar answered Oct 28 '22 07:10

Andrew Rozdolsky