Infinite Loop of layoutAttributesForElementsInRect

freeze, infinite-loop, ios, objective-c, uicollectionview

Solution

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

Problem

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.

Original source

Related problems