繁体   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