Reload UICollectionView header or footer?

前端 未结 10 1186
余生分开走
余生分开走 2020-12-08 02:35

I have some data that is fetched in another thread that updates a UICollectionView\'s header. However, I\'ve not found an efficient way of reloading a supplementary view suc

10条回答
  •  抹茶落季
    2020-12-08 03:11

    Swift 3/4/5 version:

    collectionView.collectionViewLayout.invalidateLayout()
    

    Caution!

    If you change the number of collectionView items at the same time (for example you show the footer only if all cells were loaded), it will crash. You need to reload the data first, to make sure that the number of items is the same before and after invalidateLayout():

    collectionView.reloadData()
    collectionView.collectionViewLayout.invalidateLayout()
    

提交回复
热议问题