Ios 在UICollectionView中显示下载的图像

Ios 在UICollectionView中显示下载的图像,ios,objective-c,uicollectionview,uicollectionviewcell,Ios,Objective C,Uicollectionview,Uicollectionviewcell,我目前正在开发一个应用程序,它允许用户拍摄图像,并将它们以数组的形式存储到解析时的唯一对象(允许多个图像等)。我希望用户下次访问对象时,他们以前保存的所有图像都会显示在UICollectionView中。我环顾四周,并遵循教程,但我得到奇怪的错误,无法得到图像显示。以下是迄今为止我拥有的所有相关代码: -下载要显示的图像的视图: 查询解析 注销时,此功能可靠地获取正确的PFF文件 UICollectionView CellForItemAtIndexPath已更新 parseImage是隐藏在U

我目前正在开发一个应用程序,它允许用户拍摄图像,并将它们以数组的形式存储到解析时的唯一对象(允许多个图像等)。我希望用户下次访问对象时,他们以前保存的所有图像都会显示在UICollectionView中。我环顾四周,并遵循教程,但我得到奇怪的错误,无法得到图像显示。以下是迄今为止我拥有的所有相关代码:

-下载要显示的图像的视图:

查询解析

注销时,此功能可靠地获取正确的PFF文件

UICollectionView CellForItemAtIndexPath已更新

parseImage是隐藏在UICollectionViewCell类中的UIImageView

我当前收到错误:[PFFile objectForKey:]:无法识别的选择器发送到实例

下面是处理collectionView图形的其余代码:

- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}

- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSLog(@"Number of items in section: %lu", (unsigned long) imagesFilesArray.count);
return [imagesFilesArray count];
}

- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

}
尽管我尽了最大的努力,我似乎还是不知道出了什么问题。interface builder中的所有项都连接到它们的正确连接。有人能帮我吗?这是我在做最后一轮QA并发布之前想要完成的最后一个大型功能:)非常激动,因为这是我的第一个个人应用程序,但正如你所能想象的那样,很沮丧

再次编辑:photoHandler文件

h

m

双重编辑-上传代码

- (void) imagePickerController:(UIImagePickerController *)picker      didFinishPickingMediaWithInfo:(NSDictionary *)info
{
_takenImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^
{
// Add object to array: Working
[_tankImagesArray addObject:_takenImage];
NSLog(@"Number of images taken: %lu", (unsigned long)_tankImagesArray.count);

// Convert array to NSData Object
NSData *imageData = [NSKeyedArchiver archivedDataWithRootObject:_tankImagesArray];

// Convert NSData Object to PFFile
PFFile *imageFile = [PFFile fileWithData:imageData];

PFQuery *tankQuery = [PFQuery queryWithClassName:@"SavedTanks"];
_tankObject = [tankQuery getObjectWithId:_passedValue];

[_tankObject setObject:imageFile forKey:@"tankImages"];

[_tankObject save];
}];
}

关于为什么我的图像可能无法显示有什么想法吗?没有,但您应该使用日志检查一些内容。如果cell.parseImage和cell.parseImage.image中的任何一个为零,则将其记录到。另外,您不应该在cellForItemAtIndexPath:中注册PhotoHandler类。这只需要执行一次,因此将其放在viewDidLoad中。最后,PhotoHandler电池是在哪里制造的?密码?在IB中,
cell.parseImage
cell.parseImage.image
都返回null。我想这就是我的问题所在;似乎在这条线的某个地方迷路了。PhotoHandler单元是在故事板中制作的,但是有一个支持类。现在将支持类发布到编辑中。好的,问题是当在情节提要中创建单元时,不应该注册类(或任何内容)。只需删除它,看看它是否有效(仅当单元格(包括其子视图)是由代码生成时才注册该类)。
无法将具有标识符parseImage的UICollectionElementKindCell类型的视图出列-必须为标识符注册nib或类,或在情节提要中连接原型单元格“
- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}

- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSLog(@"Number of items in section: %lu", (unsigned long) imagesFilesArray.count);
return [imagesFilesArray count];
}

- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

}
@interface photoHandler : UICollectionViewCell

{

}

@property (weak, nonatomic) IBOutlet UIImageView *parseImage;

@end
@interface photoHandler ()

@end

@implementation photoHandler

@synthesize parseImage;

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
    // init code
}
return self;
}
- (void) imagePickerController:(UIImagePickerController *)picker      didFinishPickingMediaWithInfo:(NSDictionary *)info
{
_takenImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^
{
// Add object to array: Working
[_tankImagesArray addObject:_takenImage];
NSLog(@"Number of images taken: %lu", (unsigned long)_tankImagesArray.count);

// Convert array to NSData Object
NSData *imageData = [NSKeyedArchiver archivedDataWithRootObject:_tankImagesArray];

// Convert NSData Object to PFFile
PFFile *imageFile = [PFFile fileWithData:imageData];

PFQuery *tankQuery = [PFQuery queryWithClassName:@"SavedTanks"];
_tankObject = [tankQuery getObjectWithId:_passedValue];

[_tankObject setObject:imageFile forKey:@"tankImages"];

[_tankObject save];
}];
}