我试图将页脚添加到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;
- }
但我的应用程序不断崩溃,下面是日志,
*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:],/SourceCache/UIKit/UIKit-2380.17/UICollectionView.m:2249
任何帮助表示赞赏.
谢谢.
解决方法
在您的代码中为什么要对标题视图进行dequeing并向其添加页脚?
这种方法的正常实现是:
- - (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;
- }