0

我正在尝试使用 aUICollectionView与 a 协作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 OwnermyUICollectionView中,我使用:

- (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],它不能再次呈现而不会崩溃

2013-03-10 22:11:35.448 CapifyPro[21115:907] -[UICollectionViewCell setThumb:]: unrecognized selector sent to instance 0x1e593320
2013-03-10 22:11:35.450 CapifyPro[21115:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell setThumb:]: unrecognized selector sent to instance 0x1e593320'

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

4

1 回答 1

0

如果使用由 XIB 或 storyBoardCell 使用的 UICollectionViewCell。简单地将您的 imageThumb imageView 拖放到 MemeCell.h。删除 MemeCell.m 中的二传手。然后按顺序设置:

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;
于 2013-03-11T02:44:56.057 回答