我正在尝试使用UICollectionView
与UICollectionViewCell
合作显示图像的缩略图。在我的应用程序中使用的UICollectionViewCell
的是自定义的(简单)的子类:UICollectionView崩溃?
#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
在我UICollectionView
的File'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]
解雇本身后,不能再没有与
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'
崩溃谁能洞察呈现的?
错误消息是说你正在尝试将setThumb发送到UICollectionViewCell,而不是你的自定义单元格。你是否正在用这个单元在IB中做任何事情,或者你是否为单元注册了一个班级或笔尖? – rdelmar 2013-03-11 02:35:04
我在'viewDidLoad'中注册了一个类,并且将'collectionView:cellForItemAtIndexPath:'改为了我编辑的文章 – HighFlyingFantasy 2013-03-11 02:37:24
尝试取出if(!nibLoaded)子句,并注册nib而不是类。然后,如果没有单元出队,系统会自动从nib文件中获取一个单元。 – rdelmar 2013-03-11 02:40:58