我一直在努力使我的應用程序在iOS 8上運行,並嘗試使用來自restful API的數據。從webservice獲取響應後,我試圖從委託方法重新加載collectionview。我從numberOfItemsInSection的數組中獲取有效的數字計數爲5,但cellForItemAtIndexPath沒有被調用。UICollectionview cellForItemAtIndexPath在iOS 8中重新加載時未得到調用
我在一個場景中看到,如果我硬編碼numberOfItemsInSection返回計數爲5,然後cellForItemAtIndexPath完全調用時重新加載。
這裏是我的代碼片段:
#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:'的代碼? –
你確定「我的數組中有效數字數爲5」numberOfItemsInSection「?你怎麼知道的? – anhtu
我確實調試了數組數並打印計數,最初當視圖加載計數打印「0」後,從API接收對象的計數打印並返回「5」。我很確定。 – Sathish