Thursday, 29 October 2020

Using UICollectionLayoutListConfiguration with storyboards

Can you use the new UICollectionLayoutListConfiguration API in iOS 14 with collection views in storyboards?

I have a UICollectionViewController in a storyboard, which I configure with a custom list layout below:

var config = UICollectionLayoutListConfiguration(appearance: .plain)
let layout = UICollectionViewCompositionalLayout.list(using: config)
collectionView.setCollectionViewLayout(layout, animated: false)
collectionView.dataSource = dataSource

(In storyboards collection views can only be set with flow or custom layouts)

This uses a standard diffable data source:

return UICollectionViewDiffableDataSource(collectionView: collectionView) { (collectionView, indexPath, item) in
    guard let cell = collectionView.dequeueReusableCell(
        withReuseIdentifier: "SomeCell",
        for: indexPath
    ) as? SomeCell else {
        fatalError("Couldn't dequeue cell \(reuseIdentifier)")
    }

    cell.setItem(item)
    return cell
}

However I get some really weird behaviour, such as IBOutlets being nil when rotating the screen, despite everything working fine before rotation.

I've found no good way to debug what is going on here, the stack trace looks correct and the cell's class is initilised and this is running on the main thread.

Strange nil IBOutlot



from Using UICollectionLayoutListConfiguration with storyboards

No comments:

Post a Comment