ios – UICollectionView页脚

前端之家收集整理的这篇文章主要介绍了ios – UICollectionView页脚前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将页脚添加到UICollectionView.

以下是我的代码,

UICollectionView通过IB添加

在viewDidLoad我注册页脚,

  1. [mCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];

并实施以下方法

  1. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  2. {
  3. UICollectionReusableView *reusableview = nil;
  4.  
  5. if (kind == UICollectionElementKindSectionFooter) {
  6. UICollectionReusableView *headerView = [mCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"footer" forIndexPath:indexPath];
  7.  
  8. [headerView addSubview:mFooterView];
  9. reusableview = headerView;
  10. }
  11. return reusableview;
  12. }

但我的应用程序不断崩溃,下面是日志,

*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:],/SourceCache/UIKit/UIKit-2380.17/UICollectionView.m:2249

任何帮助表示赞赏.

谢谢.

解决方法

在您的代码中为什么要对标题视图进行dequeing并向其添加页脚?

这种方法的正常实现是:

  1. - (UICollectionReusableView *)collectionView:(UICollectionView *)theCollectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)theIndexPath
  2. {
  3.  
  4. UICollectionReusableView *theView;
  5.  
  6. if(kind == UICollectionElementKindSectionHeader)
  7. {
  8. theView = [theCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:theIndexPath];
  9. } else {
  10. theView = [theCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:theIndexPath];
  11. }
  12.  
  13. return theView;
  14. }

猜你在找的iOS相关文章