ディレクトリに保存された画像を呼び出して、UICollectionView に表示できません。私が何かを忘れた可能性はありますか?何が起こっているのかを確認できるようにログを追加しました.iとjの両方が出てきますが、クラッシュします
terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<HatsCell 0x208940c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key image.'
*** First throw call stack:
(0x3467c2a3 0x3c36097f 0x3467bf99 0x34ee91d9 0x366282b9 0x34ee4f2b 0x3460261b 0x3662131d 0x3689f077 0x3689f56b 0xa0911 0x3689a02d 0x3689af25 0x3689c7bb 0x36487803 0x36231d8b 0x36231929 0x3623285d 0x36232243 0x36232051 0x36231eb1 0x346516cd 0x3464f9c1 0x3464fd17 0x345c2ebd 0x345c2d49 0x3818a2eb 0x364d8301 0x8e7cd 0x3c797b20)
libc++abi.dylib: terminate called throwing an exception
これは私のリコール コードです。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
allImagesArray = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *location=@"hats";
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
collectionHats.delegate =self;
collectionHats.dataSource=self;
for(NSString *str in directoryContent){
NSLog(@"i");
NSString *finalFilePath = [fPath stringByAppendingPathComponent:str];
NSData *data = [NSData dataWithContentsOfFile:finalFilePath];
if(data)
{
UIImage *image = [UIImage imageWithData:data];
[allImagesArray addObject:image];
}}}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
NSLog(@"j");
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [allImagesArray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseID = @"ReuseID";
HatsCell *mycell = (HatsCell *) [collectionView dequeueReusableCellWithReuseIdentifier:reuseID forIndexPath:indexPath];
return mycell;
}
これは、帽子セルの.h用です
import <UIKit/UIKit.h>
@interface HatsCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *imageInCell;
@end