3

我有一個UICollectionView,我正在使用dequeueReusableCellWithReuseIdentifier重用單元格。第二次調用cellForItemAtIndexPath時,會返回一個隱藏的單元格 - 因此單元格不會顯示在我的UICollectionView中。我嘗試對單元格進行硬編碼,使其不被隱藏 - 但這不起作用,即使將其設置爲「NO」,隱藏屬性仍保持爲「YES」。什麼導致細胞被隱藏 - 這又如何被否定?UICollectionViewCell dequeueReusableCellWithReuseIdentifier給出了一個隱藏的單元格

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    SFReceiptCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; 
    [cell setHidden:NO]; 

    NSLog(@"cell.hidden = %d", cell.hidden); 
    ... 

這顯示在日誌中:

cell.hidden = 1

沒有哪裏是代碼的細胞中被隱藏的 - 所以我不知道發生什麼事導致這種情況發生。

+0

您是否爲其他視圖設置了隱藏?如果沒有,請檢查您的重用邏輯。 – Lumialxk

+0

同樣的問題發生在我身上,你是否也修復過它? – anoop4real

回答

1

剛纔有同樣的問題。我花了3個小時進行調試,並試圖設置.hidden = false沒有成功。 原來,補充說:

override func applyLayoutAttributes(layoutAttributes:UICollectionViewLayoutAttributes) 
{ 
    super.applyLayoutAttributes(layoutAttributes) 
    self.updateSubviews() 
} 

UICollectionViewCell子類中,我使用的項目解決了這個問題。 即時通訊使用updateSubviews()更新幀,因爲我不想在單元格中使用自動佈局。

相關問題