iOS UICollectionView 添加UICollect

2017-03-15  本文已影响765人  ali_hilo

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

解决:划线部分

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

}

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

上一篇 下一篇

猜你喜欢

热点阅读