Questions tagged [uicollectionviewdiffabledatasource]
75 questions
8
votes
0 answers
Diffable Data Source Scrolls to Top After Applying Snapshot with All New Data in Collection View
I have a collection view (using a compositional layout and a diffable data source) that has a segmented control in its header. When the control value changes, the cells update to a different UICollectionViewCell class with all new data. It mostly…

Nstandage
- 93
- 5
8
votes
1 answer
Does UICollectionViewDiffableDataSource work with UICollectionViewDataSourcePrefetching?
My understanding is that UICollectionViewDataSourcePrefetching is built for UICollectionViewDataSource, whereas UICollectionViewDiffableDataSource doesn't seem to have any documentation around prefetching.

pizza7
- 441
- 4
- 17
7
votes
2 answers
UICollectionViewCompositionalLayout optional sections
I have looked at this question, which is similar: How to deal with empty items section in UICollectionView CompositionalLayout, but the answer there seems to be either leave sections out in the snapshot (which I do, but that leaves another problem,…

ashipma
- 423
- 5
- 15
7
votes
3 answers
Swift: How to Optionally return a header for a collection view section?
I have a UICollectionViewDiffableDataSourcelike so:
var data:UICollectionViewDiffableDataSource!
I define my section header's layout like so:
let header = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize:…

Josh Arnold
- 249
- 4
- 8
6
votes
1 answer
Why is UICollectionViewDiffableDataSource reloading every cell when nothing has changed?
I've created the following demo view controller to reproduce the issue in a minimal example.
Here I'm applying a snapshot of the same data repeatedly to the same collection view using UICollectionViewDiffableDataSource and every time all of the…

Logan Shire
- 5,013
- 4
- 29
- 37
6
votes
1 answer
UICollectionViewDiffableDataSource cellProvider called more often than expected
I'm using the UICollectionViewDiffableDataSource to populate my UICollectionView. After receiving a list of items via REST API, I create a new snapshot and apply it like this:
DispatchQueue.main.async {
var snapshot =…

Medwe
- 318
- 1
- 12
5
votes
0 answers
UICollectionViewDiffableDataSource - Crash when having equal items with different hash
I am using UICollectionViewDiffableDataSource to fill UICollectionView with data. My understanding is that DiffableDataSource compares items by using == and then if items are equal it compares hash values to see if something changed.
But according…

Josip B.
- 2,434
- 1
- 25
- 30
5
votes
1 answer
How can I use UICollectionViewDiffableDataSource reorderHandlers with a custom compositional layout?
As of iOS 14, UICollectionViewDiffableDataSource has a reorderHandlers property. It's demonstrated in some sample code and talked about in WWDC 2020 session on Advances in Diffable Data Sources. The presenter states that you have to provide a…

Tom Hamming
- 10,577
- 11
- 71
- 145
4
votes
3 answers
How do you use multiple data models in a diffable data source?
I've currently hit a wall while trying to develop the search view within my application. I've attempted to place a collection view within a table view cell, as well as use the traditional collection view data source delegates (cell for row at etc.)…

Andrew Kestler
- 57
- 1
- 8
4
votes
1 answer
UICollectionVIew Compositional Layout & DiffableDataSource, how to enable data prefetching?
How to enable data prefetching when using the new Compositional Layout & DiffableDataSource?
Before, we can achieve this by conforming a custom data source object, like,
class CustomDataSource: NSObject, UICollectionViewDataSource,…

zrfrank
- 2,631
- 1
- 12
- 18
4
votes
1 answer
UICollectionViewDiffableDataSource crash: Invalid parameter not satisfying: itemCount
I am using a UICollectionView with UICollectionViewDiffableDataSource and fetching data both asynchronously and synchronously to populate the view. The app crashes with this message: "Terminating app due to uncaught exception…

Rachel
- 81
- 7
4
votes
0 answers
UICollectionViewCompositionalLayout orthogonal section willDisplayCell analytics
I'm using Collection View Compositional Layout and need to have accurate analytics for "userViewedCell" events for orthogonally scrolling sections. I had been using collectionView(willDisplay:forItemAt) to detect when a cell is about to be shown,…

gracie
- 41
- 2
3
votes
0 answers
UICollectionViewDiffableDataSource updates horizontally scrolling section incorrectly, but handles vertical section updates just fine
I’m attempting to create a collection view with 2 sections which supports live reloading of data. Leveraging UICollectionVIewDiffableDataSource, this should be quite straightforward.
final class ViewController: UIViewController {
private…

thexande
- 1,645
- 16
- 23
3
votes
1 answer
Crash UICollectionViewFlowLayout when applying snapshot on iOS 15
I have a UICollectionView with a simple UICollectionViewFlowLayout. On iOS 15 when first loading the view and setting the items an exception occurs.
This is called on the main thread when the items are set:
var snapshot =…

Marcel
- 6,393
- 1
- 30
- 44
3
votes
1 answer
How to handle empty state when using diffable data source - UICollectionViewDiffableDataSource?
When using traditional UICollectionView, we often use the following code to handle empty state:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if items.count == 0 {
// Display empty…

imgroot
- 131
- 3
- 11