Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectinComponent如何解决缓存? #2

Open
mistdon opened this issue Oct 24, 2017 · 2 comments
Open

CollectinComponent如何解决缓存? #2

mistdon opened this issue Oct 24, 2017 · 2 comments

Comments

@mistdon
Copy link

mistdon commented Oct 24, 2017

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

@mistdon
Copy link
Author

mistdon commented Oct 24, 2017

- (__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

@rickytan
Copy link
Owner

自定义一个 cell 子类:

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

@implementation MyCell

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants