我正在嘗試使用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