小编Rev*_*vin的帖子

viewForSupplementaryElementOfKind未在自定义UICollectionViewLayout上调用

我创建了一个自定义的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 …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewlayout uicollectionreusableview

11
推荐指数
2
解决办法
9532
查看次数