sub*_*ale 6 objective-c ios uicollectionview
我试图将页脚添加到UICollectionView.
以下是我的代码,
UICollectionView通过IB添加
在viewDidLoad我注册页脚,
[mCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
Run Code Online (Sandbox Code Playgroud)
并实施以下方法
- (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;
}
Run Code Online (Sandbox Code Playgroud)
但我的应用程序不断崩溃,下面是日志,
***断言失败 - [UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:],/ SourceCache/UIKit/UIKit-2380.17/UICollectionView.m:2249
任何帮助表示赞赏.
谢谢.
Boa*_*ssi 13
在您的代码中为什么要对标题视图进行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;
}
Run Code Online (Sandbox Code Playgroud)