我正在试图添加页脚到UICollectionView。
以下是我的代码,
UICollectionView是通过IB添加的
在viewDidLoad中我注册了页脚,
[mCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];并实现了以下方法
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionFooter) {
UICollectionReusableView *headerView = [mCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"footer" forIndexPath:indexPath];
[headerView addSubview:mFooterView];
reusableview = headerView;
}
return reusableview;
}但我的申请一直在崩溃下面是日志,
*断言在_dequeueReusableViewOfKind:withIdentifier:forIndexPath:,/SourceCache/UIKit/UIKit-2380.17/UICollectionView.m:2249中失败
任何帮助都是非常感谢的。
谢谢。
发布于 2013-10-23 10:28:26
在您的代码中,为什么要查询页眉视图并将页脚添加到其中?
这一方法的正常实施是:
- (UICollectionReusableView *)collectionView:(UICollectionView *)theCollectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)theIndexPath
{
UICollectionReusableView *theView;
if(kind == UICollectionElementKindSectionHeader)
{
theView = [theCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:theIndexPath];
} else {
theView = [theCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:theIndexPath];
}
return theView;
}发布于 2019-05-16 12:45:09
斯威夫特4
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
var myView = UICollectionReusableView()
if kind == UICollectionView.elementKindSectionHeader {
myView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: myHeader, for: indexPath)
} else {
myView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: myFooter, for: indexPath)
}
return myView
}https://stackoverflow.com/questions/17878525
复制相似问题