0

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私の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]クラッシュせずに再度表示することはできません。

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を使用してください。imageThumbimageViewをMemeCell.hにドラッグドロップするだけです。MemeCell.m内のセッターを削除します。次に、dequenceに設定します。

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

MemeCellの場合はXibはありません。初期化して、memeCell.contentViewのサブビューとしてimageThumbを追加してください。

- (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 に答える