0

方法

-(void)prepareForReuse 

在我的集合视图中,从未调用单元格 - 导致我怀疑UICollectionView没有正确出列单元格。这会导致迟钝和记忆问题。

我已经按如下方式设置了我的 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
}

编辑

附加代码

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;
}
4

2 回答 2

0

请发布包含您的 UICollectionViewCell 的 xib/场景的屏幕截图,显示它的检查器。或者,如果您的单元格完全由代码构建,请发布将您的类注册到集合视图的相关代码。通常发生这种情况是因为单元标识符中的拼写错误。

于 2013-10-16T14:36:54.603 回答
0

你似乎没有在initMyView任何地方打电话。

于 2013-10-16T15:56:22.083 回答