我遇到一个问题,viewForSupplementaryElementOfKind
委托(delegate)函数从未检测到 UICollectionElementKindSectionFooter
。
因此,创建了页眉,但从未创建页脚。
我还实现了委托(delegate) 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
是可行的,但我试过了,它也不起作用
最佳答案
确保你有一个实现
func collectionView(
_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
referenceSizeForFooterInSection section: Int
) -> CGSize
此外,此函数应返回一个非零大小。我发现如果有任何机会返回零维,UIKit 将推断没有页脚需要出队并且不会调用您的 viewForSupplementaryElementOfKind
函数,或者 supplementaryViewProvider
如果您重新使用 iOS 13 中引入的可区分数据源。
关于ios - 从未在 viewForSupplementaryElementOfKind 中检测到 UICollectionElementKindSectionFooter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40540455/