【问题标题】:viewForSupplementaryElementOfKind is not being called in iOS 13 device在 iOS 13 设备中未调用 viewForSupplementaryElementOfKind
【发布时间】:2020-06-11 13:01:26
【问题描述】:

我尝试使用集合视图委托方法viewForSupplementaryElementOfKind 在我的集合视图布局中添加页脚视图,但在重新加载集合视图时它没有被调用。

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:viewForSupplementaryElementOfKind:atIndexPath:),但这对我不起作用。

【问题讨论】:

  • 请显示更多上下文。谢谢。
  • 我更新问题@matt。它在实时应用程序中运行良好,但是当我今天运行此代码时,它会产生问题。
  • 好吧,这不是真正的代码。
  • 我只有这个代码。你能帮我看看这段代码有什么问题吗?
  • 它不可能是你的真实代码。您尚未声明 SeatArrangementViewController 是 UIViewController。将您的真实代码复制并粘贴到问题中。

标签: ios swift xcode uicollectionview


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

【讨论】:

    猜你喜欢
    • 2019-01-17
    • 2020-02-05
    • 2020-02-04
    • 1970-01-01
    • 2019-12-23
    • 2020-10-16
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多