简体   繁体   English

将单元出队时,iOS7 UICollectionViewCell不被重用

[英]iOS7 UICollectionViewCell not being reused when dequeuing cell

the method 方法

-(void)prepareForReuse 

In my collection view cell is never called - leading me to suspect that the UICollectionView is not dequeuing cells properly. 在我的集合视图中,从不调用单元格-导致我怀疑UICollectionView没有正确地使单元出队。 This is causing lagyness and memory issues. 这会导致延迟和内存问题。

I've set up my collectionView as follows: 我已经将我的collectionView设置如下:

static NSString *cellIdentifier = @"Mycell";
-(void)initMyView
{
    [self.collectionView registerClass:[UrlLoadableCollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier];
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
            UrlLoadableCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:index];
    if (cell.contentView.frame.size.width < 100) // tried removing this as well but didn't help
    {
        cell.layer.shouldRasterize = YES;
        cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
    } else {
        cell.layer.shouldRasterize = NO;
    }
                // prepare cell
}

EDIT 编辑

Additional Code 附加代码

static NSString *cellIdentifier = @"Mycell";

@interface UIThumbnailGalleryView
@property (nonatomic,strong) UICollectionView *collectionView;

@end


@implementation UIThumbnailGalleryView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView:frame];

    }
    return self;
}
-(void)initView:(CGRect)frame
{
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:[self getGalleryLayout]];

    [self.collectionView registerClass:[UrlLoadableCollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [self addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor blackColor];
    [self.collectionView setShowsHorizontalScrollIndicator:NO];
    [self.collectionView setShowsVerticalScrollIndicator:NO];
}


-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    UrlLoadableCollectionViewCell *cell = [self.dequeueReusableCellAtIndex:indexPath];
}

-(UrlLoadableCollectionViewCell *)dequeueReusableCellAtIndex:(NSIndexPath *)index
{
    UrlLoadableCollectionViewCell *cell = (UrlLoadableCollectionViewCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:index];
    return cell;
}

-(UICollectionViewFlowLayout *)getGalleryLayout
{

        UICollectionViewFlowLayout *galleryLayout = [[UICollectionViewFlowLayout alloc] init];
        [galleryLayout setItemSize:CGSizeMake(77, 77)];
        galleryLayout.minimumInteritemSpacing = 3.0;
        galleryLayout.minimumLineSpacing = 3.0;
        // iOS 6 - might need to uncomment
        //[galleryLayout setSectionInset:UIEdgeInsetsMake(44,5, 44, 5)];

    return galleryLayout;
}

Please post a screenshot of the xib/scene that contains your UICollectionViewCell showing it's inspector. 请发布包含您的UICollectionViewCell的xib / scene的屏幕快照,以显示其检查器。 Or, if you're cell is constructed entirely in code, post the relevant code that registers your class with the collection view. 或者,如果您的单元格完全是用代码构造的,请在集合视图中发布用于注册您的类的相关代码。 Usually when this occurs it's because of a typo in the Cell Identifier. 通常,发生这种情况是由于单元标识符中的错字。

您似乎没有在任何地方调用initMyView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重用单元格时,UICollectionViewCell的文本显示在其他位置 - UICollectionViewCell's text is appearing somewhere else when the cell is reused 在UICollectionViewCell中使用计时器添加倒计时标签的最佳方法,即使在单元格被重用后也能正常工作 - The best way of adding countdown label with timer in UICollectionViewCell which works fine even after cell is being reused 单元被过度使用 - Cell is being overzealously reused iOS 6/7中“无法使用表格单元索引路径”消息的含义是什么? - What is the meaning of the “no index path for table cell being reused” message in iOS 6/7? 如何确定dequeueReusableCellWithIdentifier返回的单元格是否在iOS 6中重用? - How do I determine if a cell returned by dequeueReusableCellWithIdentifier is being reused in iOS 6? iOS自定义单元格,标签重用时标签显示错误文本 - IOS custom cell with labels showing wrong text when cell reused 仅在重用单元格时,在UICollectionViewCell的子视图上调用removeFromSuperview不适用于首次加载 - Calling removeFromSuperview on subview in UICollectionViewCell does not work on first load, only when cell is reused 发出出列UICollectionViewCell的问题 - Issue dequeuing UICollectionViewCell UICollectionViewCell在iOS7和iOS 8上的大小不同 - UICollectionViewCell has a not the same size on iOS7 and iOS 8 计时器在 UItableview 单元格中重用 - Timer being reused in UItableview cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM