UICollectionView do not reuse cells

in.disee picture in.disee · Oct 9, 2013 · Viewed 14.7k times · Source

I am having trouble with reuse cells and UICollectionView on iOS 7. My code works fine on iOS 6 but in iOS 7 it does not reuse the cell after calling dequeueReusableCellWithReuseIdentifier (do not call prepareForReuse).

Even this code https://developer.apple.com/library/ios/samplecode/CollectionView-Simple/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012860 does not reuse cell on iOS7 (but works well on iOS6), on every dequeueReusableCellWithReuseIdentifier it creates a new cell and deallocates the old one. Is there some new stuff that prevents cells to be reused?

My cells are big enough that they it is very inefficient to not reuse them. I've notice lag on iOS 7, but not on iOS 6, because they are not being reused in iOS 7.

Answer

Alessandro Orrù picture Alessandro Orrù · Nov 22, 2013

I was experiencing the same exact issue on my iPad 3 today (just one out of three iPad 3 I tested out), and I found out it is related to global Accessibility settings. The solution is to double check that every option in accessibility panel is disabled. I think that some options (like bigger fonts, for example) could stay enabled, but I haven't checked which one in details.

Explanation

Looking at the stack trace you can see this:

#0  0x003121ce in -[MyCollectionViewCell initWithFrame:]
#1  0x32f945ec in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
#2  0x04466656 in -[UICollectionViewAccessibility(SafeCategory) _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
#3  0x32f9414a in -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:]
#4  0x001767cc in -[MyCollectionView collectionView:cellForItemAtIndexPath:]

As you can see there is a call to -[UICollectionViewAccessibility(SafeCategory) _dequeueReusableViewOfKind:withIdentifier:forIndexPath:] that references something about Accessibility. So I went to Accessibility settings in Settings app, and I found out that my setting for Accessibility Shortcut was "switch control" instead of nothing. So I disabled it, I ran again the app and my stack trace now was fine:

#0  0x00313658 in -[MyCollectionViewCell prepareForReuse]
#1  0x32f942e6 in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
#2  0x32f9414a in -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:]
#3  0x001767cc in -[MyCollectionView collectionView:cellForItemAtIndexPath:]