我已将collectionView移至我的ViewController
,创建了IBOutlet,与dataSource
和delegate
建立了连接,添加了协议:UICollectionViewDataSource
,UICollectionViewDelegate
,{{ 1}},还添加了方法:
UICollectionViewDelegateFlowLayout
我还创建了自定义单元格并将其添加到- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section
{
return 5;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (AdImageCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
AdImageCell *cell = (AdImageCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"AdImageCellIdentifier" forIndexPath:indexPath];
cell.imageView1.image = [UIImage imageNamed:@"3.jpg"];
return cell;
}
:
viewDidLoad
但我的问题是 [self.collectionView registerNib:[UINib nibWithNibName:@"AdImageCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"AdImageCellIdentifier"];
和numberOfItemsInSection
仅被调用,而不是numberOfSectionsInCollectionView
。为什么呢?
答案 0 :(得分:0)
如果您从collectionView registerClass:forCellWithReuseIdentifier
方法移除viewDidLoad
,有时它会起作用。
collectionView:cellForItemAtIndexPath: never gets called
希望它会帮助你..