【发布时间】:2014-08-18 10:40:48
【问题描述】:
我已将 collectionView 移至我的 ViewController,创建了 IBOutlet,与 dataSource 和 delegate 建立了连接,添加了协议:UICollectionViewDataSource、UICollectionViewDelegate、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 只被调用,而不是 cellForItemAtIndexPath。为什么?
【问题讨论】:
标签: ios objective-c uiviewcontroller storyboard uicollectionview