我试图将页脚添加到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; }
原文地址:https://www.jb51.cc/iOS/330722.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。