我对 Collection View 单元格有疑问。当我的 Collection View 首次加载时,它会显示如下项目:
- (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;
}
在这些方法中是将 subview 添加到自定义单元格类的逻辑,这取决于特定情况。
一切正常,但是,当重新加载 Collection View 时(我确实在 1 秒后强制重新加载)一些单元格被重复使用并放置在其他单元格上,因此,它显示“旧”图像和 subview 。
我可以看到强制 uicollection View 停止重复使用单元格的可能解决方案(即,每次加载新单元格)。有什么办法吗?
最佳答案
尝试实现 prepareForReuse
方法来重置自定义 UICollectionViewCell
中的旧内容
-(void)prepareForReuse {
[super prepareForReuse];
self.yourimageview.image = nil; //and etc.
}
关于ios - UICollectionView 重用单元格问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38456395/