繁体   English   中英

UICollectionView崩溃?

[英]UICollectionView Crash?

我正在尝试与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

UICollectionViewFile's Owner中,我使用:

- (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]的委托中[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'

谁能提供见识?

如果使用,则使用XIB或storyBoardCell的UICollectionViewCell。 简单地将您的imageThumb imageView拖放到MemeCell.h。 在MemeCell.m中删除您的二传手。 然后设置双端:

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

如果是MemeCell no 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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM