【发布时间】:2015-08-15 03:44:23
【问题描述】:
我一直在努力让我的应用程序在 iOS 8 上运行,并尝试使用来自 RESTful API 的数据。从网络服务获得响应后,我尝试从委托方法重新加载集合视图。我从数组中为 numberOfItemsInSection 获取有效数字计数为 5,但未调用 cellForItemAtIndexPath。
我在一种情况下看到,如果我将 numberOfItemsInSection 返回计数硬编码为 5,那么在重新加载时完美调用 cellForItemAtIndexPath。
这是我的代码 sn-p:
#pragma mark = UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [offerModel.arrayOffers count];
}
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
cellForItemAtIndexPath:(NSIndexPath*)indexPath {
NSString *identifier = @"OfferCell";
static BOOL nibMyCellloaded = NO;
if(!nibMyCellloaded){
UINib *nib = [UINib nibWithNibName:identifier bundle: nil];
[offerCollectionView registerNib:nib forCellWithReuseIdentifier:identifier];
nibMyCellloaded = YES;
}
OfferCell* cell = (OfferCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier
forIndexPath:indexPath]; // // Commented binding values return
cell;
}
- (void)updateOfferList{
[offerCollectionView reloadData];
}
-(void)viewDidLoad{
[offerCollectionView registerClass:[OfferCell class] forCellWithReuseIdentifier:@"OfferCell"];
// set up delegates
self.offerCollectionView.delegate = self;
self.offerCollectionView.dataSource = self;
}
请帮助我。快速回复最受赞赏。谢谢
【问题讨论】:
-
为什么不编辑您的问题以显示
numberOfItemsInSection:的代码? -
您确定“我从我的 numberOfItemsInSection 数组中获得的有效数字计数为 5”?你怎么知道的?
-
我确实调试了数组计数并打印了计数,最初当视图加载计数时打印“0”,从 API 接收到对象后,计数打印并返回“5”。我很确定。
-
专家对此问题有何更新?
-
您确定您的collectoinView 是offercollectionview 类型吗?更进一步:你应该在你的 iboutlet 上设置委托,如果 collectionView 是你的实际 UI 项,那么你应该调用 self.collectoinView.reloadData
标签: ios objective-c uicollectionview