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.
If you're working entirely in code, you can register a UICollectionViewCell subclass for use with your collection view, so that new cells are dequeued and re-use automatically by the system. If a cell doesn't already exist that can be re-used, a new one will be created automatically.
Tableiw is a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic. 2. UICollectionView is the model for displaying multidimensional data .
The collection view presents items onscreen using a cell, which is an instance of the UICollectionViewCell class that your data source configures and provides. In addition to its cells, a collection view can present data using other types of views.
Build and Run the project and select the Edit Button. Select a few cells and press the Trash button to remove the items.
You can use UICollectionViewCell as-is or subclass it to add additional properties and methods. The layout and presentation of cells is managed by the collection view and its corresponding layout object. To configure the content and appearance of your cell, you can set its contentConfiguration and backgroundConfiguration.
A custom cell of a UICollectionView list is a subclass of UICollectionViewListCell. It has only 1 task — generate a properly configured content configuration object based on the state (selected, highlighted, disabled, etc.) of the cell and then assign the configuration to itself.
A content view is a UIView subclass that conforms to the UIContentView protocol. It defines the layout and appearance of the custom cell. It is also in charge of displaying the correct data and appearance based on the provided content configuration.
It has only 1 task — generate a properly configured content configuration object based on the state (selected, highlighted, disabled, etc.) of the cell and then assign the configuration to itself. To summarize, the custom cell will create and assign a content configuration object to itself.
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.
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:]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With