我創建了一個UICollectionViewCell看起來像這樣UICollectionViewCell無法識別的選擇發送到實例
#import "PhotoCell.h"
@implementation PhotoCell
@synthesize imageView;
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor clearColor];
imageView = [[UIImageView alloc] initWithFrame:(CGRect){.origin = CGPointMake(4.0f, 4.0f), .size=CGRectInset(frame, 4.0f, 4.0f).size}];
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.contentView addSubview:imageView];
}
return self;
}
@end
我從我的視圖控制器,我正在嘗試建立一個UICollectionView ..之一調用這個這是我我叫這個類
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
PhotoCell *cell = (PhotoCell *)[self.photoCollectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
NSDictionary *currentPhotoDict = [imageArray objectAtIndex:indexPath.row];
UIImage *imageForCollection = [UIImage imageWithData:[currentPhotoDict objectForKey:@"DImage"]];
// but I have no idea where to pass the imag....
cell.imageView.image = imageForCollection;
return cell;
}
問題是,我得到這個錯誤,然後我的應用程序崩潰在堆中。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell imageView]: unrecognized selector sent to instance 0x16dc1a90'
任何幫助解決這個問題將不勝感激!
UPDATE:
我創建了一個筆尖文件調用aPhotoCell和我從它刪除的UIView並添加一個UIImageView ..然後我已經改變了對象自定義類以光電,現在,我可以看到從PhotoCell的UIImageView IBOutlet我已經迷上了......但我仍然在接受相同的錯誤......我希望這是有道理的......從下面的評論和答案這是我認爲我必須做的修復..任何方式我會繼續觀看小費和答案。
似乎是委託方法 - (UICollectionViewCell *)的CollectionView:(UICollectionView *)的CollectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath沒有返回光電對象 – bhawesh