UICollectionView崩溃?

时间:2013-03-11 02:18:00

标签: ios uicollectionview uicollectionviewcell

我正在尝试与UICollectionView合作使用UICollectionViewCell来显示图片的缩略图。我的应用中使用的UICollectionViewCell是自定义(简单)子类:

#import "MemeCell.h"

@implementation MemeCell

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

}
return self;
}

-(void)setThumb:(UIImage *)image {
    if (_thumb != image) {
        _thumb = image;
    }

    _imageThumb.image = _thumb;
}

@end

在我File's Owner的{​​{1}}中,我使用:

UICollectionView

返回一个单元格。该视图在首次显示时工作正常,但在从调用- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath { static BOOL nibLoaded = NO; if (!nibLoaded) { UINib *cellNib = [UINib nibWithNibName:@"MemeCell" bundle:nil]; [_collectionView registerNib:cellNib forCellWithReuseIdentifier:@"MemeCell"]; nibLoaded = YES; } MemeCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"MemeCell" forIndexPath:indexPath]; NSString *path = [_imageThumbs objectAtIndex:indexPath.section]; UIImage *thumb = [UIImage imageNamed:path]; [cell setThumb:thumb]; return cell; } 的委托中解除其自身后,如果没有崩溃,则无法再次显示该视图

[self dismissViewControllerAnimated:YES completion:nil]

任何人都可以提供见解吗?

1 个答案:

答案 0 :(得分:0)

如果使用XIB或storyBoardCell使用UICollectionViewCell。简单拖放你的imageThumb imageView到MemeCell.h。删除MemeCell.m中的setter。然后设置dequence:

MemeCell *cell = (MemeCell*) [cv dequeueReusableCellWithReuseIdentifier:@"MemeCell" forIndexPath:indexPath];
cell.imageThumb.image = [UIImage imageNamed:path]

在MemeCell没有Xib的情况下。请初始化并添加imageThumb作为memeCell.contentView的子视图。

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
     self.imageThumb = [[UIImageView alloc] initWithFrame:self.frame];
     [self.contentView addSubviews:self.imageThumb];

}
return self;
}

*编辑:如果您只是存储您的thumbImage,请不要显示,只需在Cell.h中声明,不需要重写setter。

property(strong,nonomatic) UIImage *thumbImage;