0

这是一个非常具体的问题,但我在我的集​​合视图上使用 UICompositional Layout 和 Diffable Data Source,在 iOS 15 上一切正常,问题在 iOS 13 上,发生了什么:

  1. 在 init 和 viewDidLoad 之后,collectionview 内容大小为零,我还检查了集合视图布局,内容大小也为零。但是单元格正在被填充,当我打印出来时,一切都在那里,除了它们的帧都为 0。

  2. 旋转屏幕后,它神奇地出现了。

  3. 通过在集合视图上调用 layoutIfNeed() 来强制集合视图在初始化后更新没有帮助。

我像这样初始化集合视图:

    let layout = createLayout() //a UICompositional layout
    self.table = MyCollectionView(items: items, columnConfigs: self.columnConfigs, layout: layout)
    stack.addArrangedSubview(table) //it's inside a stack view

对于我的自定义集合视图类 init 如下所示:

init(items: [[Item]], columnConfigs: [ColumnConfig], layout: UICollectionViewLayout){
    super.init(frame: .zero, collectionViewLayout: layout)
    self.columnConfigs = columnConfigs
    self.translatesAutoresizingMaskIntoConstraints = false
    self.backgroundColor = UIColor.clear
    self.delegate = self
    self.allowsMultipleSelection = true
    self.items = items
    self.accessibilityContainerType = .dataTable
    configureDataSource()
    configureSupplementaryView()
    createSnapshot() //diffable data source here
}

我不知道问题出在哪里或如何解决,在此先感谢您的帮助。

4

0 回答 0