【问题标题】:UICollectionElementKindSectionFooter Never Detected in viewForSupplementaryElementOfKind在 viewForSupplementaryElementOfKind 中从未检测到 UICollectionElementKindSectionFooter
【发布时间】:2016-11-11 02:58:36
【问题描述】:

我遇到了一个问题,viewForSupplementaryElementOfKind 委托函数从未检测到 UICollectionElementKindSectionFooter。

因此,创建了页眉,但从未创建过页脚。

我还实现了委托referenceSizeForHeaderInSection 和referenceSizeForFooterInSection 方法。

我也注册了NIB。

collectionView.register(UINib(nibName: "FooterCollectionReusableView", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "footerIdentifier");
collectionView.register(UINib(nibName: "HeaderCollectionReusableView", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "headerIdentifier");

这是不工作的代码。

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

    var view: UICollectionReusableView! = UICollectionReusableView();
    switch kind {
    case UICollectionElementKindSectionHeader:
        print("HEADER DETECTED");//CALLED
        break;
    case UICollectionElementKindSectionFooter:
        print("FOOTER DETECTED");//NEVER CALLED
        break;
    default:
        break;
    }

    return view;
}

谁能帮帮我?

P.S.:我读过有人说在collectionView 的布局中设置footerReferenceSize 会起作用,但我试过了,它也不起作用

【问题讨论】:

    标签: ios uicollectionview swift3 uicollectionviewcell uicollectionviewlayout


    【解决方案1】:

    确保你有一个实现

    func collectionView(
      _ collectionView: UICollectionView,
      layout collectionViewLayout: UICollectionViewLayout,
      referenceSizeForFooterInSection section: Int
    ) -> CGSize
    

    此外,此函数应返回非零大小。我发现如果有任何机会返回零维度,UIKit 将推断不需要页脚出列并且不会调用您的 viewForSupplementaryElementOfKind 函数,如果您使用的是 iOS 13 中引入的可区分数据源,则不会调用 supplementaryViewProvider。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      相关资源
      最近更新 更多