【发布时间】:2016-08-13 05:34:59
【问题描述】:
我想使用此代码将页脚添加到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
}
任何人都可以检查其中有什么问题吗??
【问题讨论】:
-
为什么你同时写了 registerNib 和 registerClass ?删除 registerNib 行。
-
我已经检查了两者仍然无法正常工作......
-
像这样写 registerClass 行:
registerClass(ProfileFooter, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter")并再次检查页脚视图的标识符是否正确。 -
我也试过了......不工作
标签: swift uicollectionview uicollectionviewlayout