Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

cocoa touch - UICollectionView do not reuse cells

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...