提问者:小点点

iOS 13设备中未调用ViewForAdministrarYelementOfKind


我尝试使用集合视图委托方法ViewForAdduterarYelementOfKind在集合视图布局中添加页脚视图,但在重新加载集合视图时不会调用它。

SeatArrangementViewController : UICollectionViewDelegate , UICollectionViewDataSource , QuiltViewDelegate ,UICollectionViewDelegateFlowLayout {

    override func viewDidLoad() {
       super.viewDidLoad()
       setCollection()         
    }

    func setCollection()  {
       self.clnSeats.collectionViewLayout.invalidateLayout()
       self.clnSeats.register(UINib(nibName: "SeatFooterView",bundle:nil),forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "SeatFooterView")
       let space = UIScreen.main.bounds.size.width - 262
       self.clnSeats.contentInset = UIEdgeInsets(top: 0, left: space/2.0, bottom: 90, right: space/2.0)

       let layout = self.clnSeats.collectionViewLayout as! QuiltView

       layout.scrollDirection = UICollectionViewScrollDirection.vertical
       layout.itemBlockSize   = CGSize(width: 50, height: 50)
       self.clnSeats.reloadData()
    }

集合视图方法

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

    switch kind{
       case UICollectionElementKindSectionFooter: .....

    }
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, blockSizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {

    // get random width and height values for the cells
    let width  = self.numberWidths[indexPath.row]
    let height = self.numberHeights[indexPath.row]

    return CGSize(width: width, height: height)
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetsForItemAtIndexPath indexPath: IndexPath) -> UIEdgeInsets {
    return UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2)
}

我还添加了@objc(collectionView:ViewForAddularYelementOfKind:atIndexPath:),但这对我不起作用。


共1个答案

匿名用户

  1. 检查您是否注册了补充视图。
  2. 检查是否设置了委托和数据源。
  3. 如果您对页脚或页眉使用自定义大小,请确保它返回的大小大于零,否则委托将停止尝试获取补充视图
func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize