我创建了一个自定义的UICollectionViewLayout,并将它放在故事板中的Collection View Controller中.我在显示项目/单元格时没有遇到太多问题.我的问题是没有调用viewForSupplementaryElementOfKind.我似乎无法确定为什么会这样.我试图回到默认布局,它确实调用它,但我需要我的自定义UICollectionViewLayout.我已经离开了NSLogs来检查并且没有调用viewForSupplementaryElementOfKind.
这是我的MyCollectionViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
viewArray = [NSMutableArray array];
//setup the delegate for vertical flow layout
[(VerticalFlowLayout*)self.collectionViewLayout setDelegate:self];
//register the headers
[self.collectionView registerNib:[ButtonHeaderCollectionReusableView nib] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[ButtonHeaderCollectionReusableView reusableID]];
//set the insets
[self.collectionView setContentInset:UIEdgeInsetsMake(23, 5, 10, 5)]; }
#pragma mark - CollectionView DataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.cardsArray count];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
NSLog(@"Number of Sections");
return 1;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Making Card");
CardCell *card …objective-c ios uicollectionview uicollectionviewlayout uicollectionreusableview