1
我试图从网站获取数据并添加到我的collectionview,但是当我调用[self.collectionView reloadData]时,它不起作用。重新加载数据后未调用UICollectionView数据源方法
所以我的代码如下:
- (void)viewDidLoad {
[PYBSkuApi getSKUList:1 andHotId:@"17" success:^(NSArray *skuList) {
self.dataSource = [NSMutableArray arrayWithArray:skuList];
[self.skuCollectionView reloadData];
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
// Data source
- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return [self.dataSource count];
}
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
....
}
问题是,当我重新加载集合视图中,self.dataSource更新后,它进入
- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView
但从来没有进入
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
我不知道为什么。
是什么'numberOfSectionsInCollectionView:'返回?是否调用了'numberOfItemsInSection'? – rmaddy
它是否返回计数? – jithin
要确保您已将集合视图的“委托”和“数据源”连接起来。 –