[英]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
在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]
的委托中[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.