RTComponentTableView icon indicating copy to clipboard operation
RTComponentTableView copied to clipboard

CollectinComponent如何解决缓存?

Open mistdon opened this issue 8 years ago • 2 comments

如题! 按照示例中的代码,延时10秒后重新设置self.components;TableComponent能够很好的解决cell的缓存,而collectionComonent没有缓存;通过涂层可以看到有很多的collection叠加在一起了

mistdon avatar Oct 24 '17 06:10 mistdon

- (__kindof UITableViewCell *)cellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath];
    self.collectionView.frame = [self collectionViewRectForBounds:cell.bounds];
    [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [cell.contentView addSubview:self.collectionView];
    return cell;
}

在cell的contentView中删除已有的collectionView

mistdon avatar Oct 24 '17 07:10 mistdon

自定义一个 cell 子类:

@interface MyCell : UITableViewCell <UICollectionViewDatasource, UICollectionViewDelegate>
@property (strong) UICollectionView *collectionView;
@end

@implementation MyCell

- (void)prepareForReuse
{
  [super prepareForReuse];
  [self.collectionView reloadData];
}
@end

这些事情交给 cell 自己做,在 prepareForReuse

rickytan avatar Oct 24 '17 11:10 rickytan