首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionView页脚

UICollectionView页脚
EN

Stack Overflow用户
提问于 2013-07-26 10:05:07
回答 2查看 17.9K关注 0票数 6

我正在试图添加页脚到UICollectionView。

以下是我的代码,

UICollectionView是通过IB添加的

在viewDidLoad中我注册了页脚,

代码语言:javascript
复制
[mCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];

并实现了以下方法

代码语言:javascript
复制
- (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中失败

任何帮助都是非常感谢的。

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-23 10:28:26

在您的代码中,为什么要查询页眉视图并将页脚添加到其中?

这一方法的正常实施是:

代码语言:javascript
复制
- (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;
}
票数 13
EN

Stack Overflow用户

发布于 2019-05-16 12:45:09

斯威夫特4

代码语言:javascript
复制
 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
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17878525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档