1
votes

I have six UICollectionView in oneView controller, depend on user selected state i want to reload collections data. my collection views is should be horizontal Scroll Direction, dynamic size cell. there is my code for set collectionViewLayout , this code work fine in all IPAD and IPHONE but there is a problem with IPHONE "5" IOS 10 and later. when call first collection view reloadData, nothing show and collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)doesn't call. in next collectionView reload data call this method call and UI update successfully. what is the problem in this devices?

private func setFlowLayout() {

  let flowLayout = UICollectionViewFlowLayout()
    flowLayout.scrollDirection = UICollectionViewScrollDirection.horizontal
    flowLayout.minimumInteritemSpacing = 10.0
    flowLayout.sectionInset = UIEdgeInsets(top: 0.0, left: 5.0, bottom: 0.0, right: 5.0)
    flowLayout.estimatedItemSize = CGSize(width: 1,height: 1)
    flowLayout.estimatedItemSize = CGSize(width: 1,height: 1)
    collectionView.collectionViewLayout = flowLayout
    collectionView.collectionViewLayout.invalidateLayout()

}
1

1 Answers

1
votes

I figured out where the problem is, it's a bug of UIKit in iOS 10. first calling invalidateLayout in viewDidLayoutSubviews

override func viewDidLayoutSubviews() {
    super.viewWillLayoutSubviews()
    collectionView.collectionViewLayout.invalidateLayout()
}

And finally calling invalidateLayout after collectionView.reloadData()