简体   繁体   English

UICollectionView重用单元格问题

[英]UICollectionView reuse cell issue

I have a problem with collection view cell. 我对集合视图单元格有问题。 When my collection view first loaded, it display items like that: 首次加载我的集合视图时,它会显示以下项目:

- (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;
}

Inside those methods are logic for adding subviews to custom cell class, which depend on certain circumstances. 在这些方法中,是将子视图添加到自定义单元类的逻辑,这取决于某些情况。

Its all work, but, when collection view reloaded (i did force reload after 1 second) some of cells are reused and placed on others, therefore, it show "old" images and subviews. 它的所有工作,但是,当收集视图重新加载(我强制重新加载1秒后)一些单元格被重用并放置在其他单元格上,因此,它显示“旧”图像和子视图。

I could see possible solution in forcing uicollection view to stop reusing cells (it is, load new cells every time). 我可以看到强制uicollection视图停止重用单元格的可能解决方案(每次都加载新单元格)。 Is there any way to do this? 有没有办法做到这一点?

Try to implement prepareForReuse method for reset your old content in your custom UICollectionViewCell 尝试实现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