2013-09-25 67 views

回答

11

最簡單的辦法是做的是編程方式(並保持你的HeaderReusableView在另一個XIB文件):

[self.collectionView registerNib:[UINib nibWithNibName:@"ItemHeaderView" bundle:nil] 
      forSupplementaryViewOfKind:UICollectionElementKindSectionHeader 
       withReuseIdentifier:kItemSectionHeaderViewID]; 

然後:

- (CGSize) collectionView:(UICollectionView *)collectionView 
        layout:(UICollectionViewLayout *)collectionViewLayout 
referenceSizeForHeaderInSection:(NSInteger)section { 
    return CGSizeMake(60.0f, 30.0f);// width is ignored 
} 

,當然還有:

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

    NSString *productId = nil; /// 

    ItemHeaderView *view = nil; 

    view = [collectionView dequeueReusableSupplementaryViewOfKind:kind 
             withReuseIdentifier:kItemSectionHeaderViewID 
               forIndexPath:indexPath]; 

    view.titleLabel.text = productId; 

    view.backgroundColor = [UIColor yellowColor]; 

    return view; 
} 
+0

我正在使用xib。你的解決方案爲我工作。最初我試圖電阻NIB'[self.selectionCollectionView registerNib:[UINib nibWithNibName:@ 「FlootThumbnailCollectionReusableView」 束:無] forCellWithReuseIdentifier:@ 「HeaderView」];' 比我改爲 '[self.selectionCollectionView registerNib: UINib nibWithNibName:@「FlootThumbnailCollectionReusableView」bundle:nil] forCellWithReuseIdentifier:@「HeaderView」]' –

相關問題