Objective c uicollectionviewcell为0时如何显示节标题

Objective c uicollectionviewcell为0时如何显示节标题,objective-c,uicollectionview,uicollectionviewcell,sections,Objective C,Uicollectionview,Uicollectionviewcell,Sections,我创建了一个UICollectionView粘性标题部分,如下所示:但当我的UICollectionViewCell为0时,隐藏中的标题部分如下所示: 在我的图片中,显示一个标题部分(索引:2),另一个标题部分是隐藏的。请引导我!!!我想要其他的节目,比如索引2 这是我的代码: - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; Flow *layo

我创建了一个UICollectionView粘性标题部分,如下所示:但当我的UICollectionViewCell为0时,隐藏中的标题部分如下所示:

在我的图片中,显示一个标题部分(索引:2),另一个标题部分是隐藏的。请引导我!!!我想要其他的节目,比如索引2

这是我的代码:

- (void)viewDidLoad {
  [super viewDidLoad];
  self.view.backgroundColor = [UIColor whiteColor];
  Flow *layout=[[Flow alloc] init];
  //layout.sectionInset = UIEdgeInsetsMake(20,0,40,0);
  //layout.itemSize = CGSizeMake(100,100);
  _collect=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout];
  _collect.backgroundColor = [UIColor clearColor];
  [_collect setDataSource:self];
  [_collect setDelegate:self];
  [_collect registerClass:[HeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
  [_collect registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
  [self.view addSubview:_collect];

  //NSLog(@"%@",self.array);
}
- (NSMutableArray*)array {
  if (!_array) {
    _array = [NSMutableArray array];
    for (NSInteger i=0; i<SectionNum; i++) {
      //NSMutableArray *inner = [NSMutableArray arrayWithObject:@"0"];
      [_array addObject:@"0"];
    }
  }
  return _array;
}
- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  return SectionNum;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  if (section == 2) {
    return 10;
  } else
    return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  static NSString *identifier = @"cellIdentifier";

  CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

  return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
  UICollectionReusableView *reusableview = nil;
  if (kind == UICollectionElementKindSectionHeader) {
    HeaderView *header = [_collect dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];

    header.backgroundColor = [UIColor colorWithWhite:0.75 alpha:.9];
    header.titleLabel.font = [UIFont systemFontOfSize:24];
    header.titleLabel.textAlignment = NSTextAlignmentCenter;
    header.titleLabel.text = [NSString stringWithFormat:@"%ld",indexPath.section];
    reusableview = header;
  }

  if (kind == UICollectionElementKindSectionFooter) {
    UICollectionReusableView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
    reusableview = footerview;
  }

  return reusableview;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  return CGSizeMake(100,100);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  CGSize headerSize = CGSizeMake(320, 50);
  return headerSize;
}
-(void)viewDidLoad{
[超级视图下载];
self.view.backgroundColor=[UIColor whiteColor];
Flow*layout=[[Flow alloc]init];
//layout.sectionInset=UIEdgeInsetsMake(20,0,40,0);
//layout.itemSize=CGSizeMake(100100);
_collect=[[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:layout];
_collect.backgroundColor=[UIColor clearColor];
[_collectsetDataSource:self];
[_CollectSetDelegate:self];
[\u collect registerClass:[HeaderView class]用于种类为:UICollectionElementKindSectionHeader with ReuseIdentifier:@“HeaderView”的SupplementView;
[\u collect registerClass:[CollectionViewCell类]forCellWithReuseIdentifier:@“cellIdentifier”];
[self.view addSubview:_collect];
//NSLog(@“%@”,self.array);
}
-(NSMutableArray*)数组{
if(!\u数组){
_array=[NSMutableArray];
对于(NSInteger i=0;i