我想使用此代码将页脚添加到UICollectionView
。我在UICollectionView布局中使用自定义布局
添加了委托和数据源方法: -
UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
viewdDidLoad()
函数中的代码: -
UINib(nibName: "ProfileFooter", bundle:nil)
collectionView!.registerNib(nibName1, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter")
collectionView.registerClass(ProfileFooter.classForCoder(), forSupplementaryViewOfKind: "ProfileFooter", withReuseIdentifier: "ProfileFooter")
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
var reusable = UICollectionReusableView()
if kind == UICollectionElementKindSectionFooter{
let ProfileFooter = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter", forIndexPath: indexPath)
ProfileFooter.backgroundColor = UIColor.redColor()
reusable = ProfileFooter
}
return reusable
}
任何人都可以检查这个错误吗?
答案 0 :(得分:1)
你忘了在出列时投出你的页脚视图。 试试这个。
override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
switch kind
{
case UICollectionElementKindSectionFooter:
let profileFooter = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter", forIndexPath: indexPath) as! ProfileFooter
profileFooter.backgroundColor = UIColor.redColor()
return profileFooter
case default:
assert(false, "Unexpected element kind")
}
}