UICollectionView重用单元格问题

Evg*_*ban 5 objective-c uitableview ios

我对集合视图单元格有问题.首次加载我的集合视图时,它会显示以下项目:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

在这些方法中,是将子视图添加到自定义单元类的逻辑,这取决于某些情况.

它的所有工作,但是,当收集视图重新加载(我强制重新加载1秒后)一些单元格被重用并放置在其他单元格上,因此,它显示"旧"图像和子视图.

我可以看到强制uicollection视图停止重用单元格的可能解决方案(每次都加载新单元格).有没有办法做到这一点?

iSa*_*hok 14

尝试实现prepareForReuse在自定义中重置旧内容的方法UICollectionViewCell

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