![](/img/trans.png)
[英]UICollectionview cellForItemAtIndexPath not getting called when collectionview reload in performBatchUpdates
[英]UICollectionview cellForItemAtIndexPath not getting called when reload in iOS 8
我一直在努力讓我的應用程序在iOS 8上運行,並嘗試使用Restful API中的數據。 從Web服務獲取響應后,我試圖從委托方法重新加載collectionview。我從數組中獲得numberOfItemsInSection的有效數字計數為5,但未調用cellForItemAtIndexPath。
我看到一種情況,如果我將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;
}
請幫我。 快速答復是最贊賞的。 謝謝
最終,我找到了阻止者的答案。 我只是使用重新加載數據來重新加載某些項目對我不起作用。 由於CV默認流程布局本身會在強制執行時自行執行一些內部操作來重新加載數據,因此,在我的情況下,我在此處使用的customviewlayout僅在加載該節時才調用layoutAttributesForItemAtIndexPath和layoutAttributesForElementsInRect 。 在這里它起作用了,因為collectionView只有一個部分,我已經重新加載了特定的部分,可以使內容正確地重新加載到CV中。
在我的API處理程序委托方法中,放置了以下代碼段,
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
[self.collectionView reloadData];
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.