美文网首页
iOS UICollectionView 添加UICollect

iOS UICollectionView 添加UICollect

作者: ali_hilo | 来源:发表于2017-03-15 10:39 被阅读765次

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

解决:划线部分

- (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;

}

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

相关文章

网友评论

      本文标题:iOS UICollectionView 添加UICollect

      本文链接:https://www.haomeiwen.com/subject/mjclnttx.html