Procuring a supplementary view is the responsibility of the collection view’s data source. However, actually init’ing one of those supplementary views (which must be subclasses of
UICollectionReusableView) MUST be done by the collection view, via the
dequeueReusableSupplemantyrView(ofKind:withReuseIdentifier:for:). It’s better to
fatalError() than it is to return a
UICollectionReusableView() - at least the error is easier to track when you
If you decide you don’t want to show a view for that particular indexPath, instead have your layout object not create attributes for that view, OR create the view, and then set the
isHidden property to 0, or set the
alpha property to 0. Alternatively, if you have a
UICollectionViewFlowLayout as the collection view’s layout, then have the appropriate method on the delegate (either
Either approach is valid and will work.
New in iOS 13, for both UICollectionView and UITableView.
See the apple documentation.
Last updated: 2020-02-23 20:45:41 -0800