[英]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.