簡體   English   中英

UICollectionView重用單元格問題

[英]UICollectionView reuse cell issue

我對集合視圖單元格有問題。 首次加載我的集合視圖時,它會顯示以下項目:

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{


    CalendarCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CalendarCell" forIndexPath:indexPath];

    [cell bindDate:_datesMgr.currentMonthItems[indexPath.row] andNowDate:_datesMgr.nowDate];


    // bind events

    if (_eventsMgr.eventsArray.count > 0){

        for (int i = 0; i < _eventsMgr.eventsArray.count ; i ++) {
            [cell bindConference:_eventsMgr.eventsArray[i]];
        }
    }


    return cell;
}

在這些方法中,是將子視圖添加到自定義單元類的邏輯,這取決於某些情況。

它的所有工作,但是,當收集視圖重新加載(我強制重新加載1秒后)一些單元格被重用並放置在其他單元格上,因此,它顯示“舊”圖像和子視圖。

我可以看到強制uicollection視圖停止重用單元格的可能解決方案(每次都加載新單元格)。 有沒有辦法做到這一點?

嘗試實現prepareForReuse方法,以重置自定義UICollectionViewCell舊內容

-(void)prepareForReuse {
   [super prepareForReuse];
   self.yourimageview.image = nil; //and etc.
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM