【问题标题】:Crash UICollectionViewFlowLayout when applying snapshot on iOS 15在 iOS 15 上应用快照时 UICollectionViewFlowLayout 崩溃
【发布时间】:2021-11-22 10:32:20
【问题描述】:

我有一个UICollectionView 和一个简单的UICollectionViewFlowLayout。在 iOS 15 上,首次加载视图并设置项目时发生异常。

设置项目时在主线程上调用:

var snapshot = NSDiffableDataSourceSnapshot<Section, PageItem>()
snapshot.appendSections([.main])
snapshot.appendItems(filteredPages)
dataSource.apply(snapshot, animatingDifferences: true)

我收到以下异常:

'the invalidation context ((null)) sent to -[UICollectionViewFlowLayout invalidateLayoutWithContext:] is not an instance of type UICollectionViewFlowLayoutInvalidationContext or a subclass'
terminating with uncaught exception of type NSException

在 iOS 14 上运行同一个项目不会崩溃。

【问题讨论】:

    标签: ios swift uikit uicollectionviewflowlayout uicollectionviewdiffabledatasource


    【解决方案1】:

    问题在于动画变化,所以从:

    dataSource.apply(snapshot, animatingDifferences: true)
    

    dataSource.apply(snapshot, animatingDifferences: false)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-04
      • 2021-12-23
      • 1970-01-01
      • 2013-10-02
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 2021-04-23
      相关资源
      最近更新 更多