iOS UICollectionView 添加UICollectionReusableView (视图重复添加)

需求:在第一组的头部添加轮播图。
问题:但是添加后,刷新时侯,会在第二组又出现轮播图。出现视图重复叠加

解决:划线部分

- (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView viewForSupplementaryElementOfKind:(NSString*)kind atIndexPath:(NSIndexPath*)indexPath;{

if([kindisEqualToString:UICollectionElementKindSectionHeader]) {

UICollectionReusableView*reusbaleView = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:headerViewIdentifierforIndexPath:indexPath];

if(indexPath.section==0){

[reusbaleViewaddSubview:[selfheaderView]];

returnreusbaleView;

}

elseif(indexPath.section==1) {

//取出reusbaleView的所有子视图移除重新添加reusbaleView

NSArray*views = reusbaleView.subviews;

for(inti =0; i < views.count; i++) {

[views[i]removeFromSuperview];

}

[reusbaleViewaddSubview:[selfsectionTitleView:indexPath.section]];

returnreusbaleView;

}

returnreusbaleView;

}

returnnil;

}

网搜没有找到办法,自己试图写了一下,该解决方法了我的问题,不过具体问题还是具体分析。 暂时这个办法,没有发现什么毛病。记录一下。 怕下次自己忘记。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容