2 years ago

#77323

test-img

Anna

UICollectionview not showing up after init on iOS 13

This is a very specific question, but I am using UICompositional Layout combined with Diffable Data Source on my collection view, everything works fine on iOS 15, the issue is on iOS 13, what's going is:

  1. After init and viewDidLoad, collectionview content size is zero, I also checked the collection view layout, the content size is also zero. But the cells are being populated, when I print it out everything is there except they all have 0 for frame.

  2. After rotating the screen, it magically shows up.

  3. Force the collection view to update after init by calling layoutIfNeed() on collection view does not help.

I am init the collection view like this:

    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

For my custom collection view class init looks like this:

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
}

I have no idea where the issue lies or how to fix it, thanks in advance for any help.

ios

swift

uicollectionview

uicollectionviewcompositionallayout

diffabledatasource

0 Answers

Your Answer

Accepted video resources