【发布时间】:2015-11-08 05:29:10
【问题描述】:
我正在尝试从网站获取数据并添加到我的 collectionview,但是当我调用 [self.collectionView reloadData] 时出现问题,它不起作用。
所以我的代码如下:
- (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被调用了吗? -
是否返回计数?
-
确保您已连接“Delegate”和“Datasource”以获取集合视图。
-
是的,它返回 8,我为自己添加了委托和数据源
-
为什么在numberOfItemsInSection中返回1而不返回[self.dataSource[section] count]; ?
标签: ios objective-c uicollectionview