Ios UICollectionView页脚
我正在尝试将页脚添加到UICollectionView 下面是我的代码 UICollectionView是通过IB添加的 在viewDidLoad中,我注册了页脚Ios UICollectionView页脚,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我正在尝试将页脚添加到UICollectionView 下面是我的代码 UICollectionView是通过IB添加的 在viewDidLoad中,我注册了页脚 [mCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"]; 并实现了以下方
[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;
}
但我的应用程序不断崩溃,下面是日志
***-[UICollectionView\u dequeueReusableViewOfKind:中的断言失败,标识符:forIndexPath:,/SourceCache/UIKit/UIKit-2380.17/UICollectionView.m:2249
感谢您的帮助
谢谢。在您的代码中,为什么要删除页眉视图并将页脚添加到其中 此方法的正常实施是:
- (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;
}
斯威夫特4号
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
}
是的,我做了同样的事情,这对我很有效!!我会认为你的答案是正确的