Ios 将图像从文档目录加载到UICollectionView

Ios 将图像从文档目录加载到UICollectionView,ios,nsmutablearray,nsarray,uicollectionview,nsfilemanager,Ios,Nsmutablearray,Nsarray,Uicollectionview,Nsfilemanager,我在将图像加载到UICollectionView时遇到问题。我正在尝试拍摄一张照片,并将其以特定名称保存到Documents文件夹,我希望在照片拍摄取消后,此照片显示在Collection视图中 到目前为止,我的图像保存在documents文件夹中,并自动添加到_stepImagesArray中,但我不知道如何加载这些图像并用它们填充uicollectionview 请帮忙,我的尝试和错误已经有一段时间了:) StepsCollectionViewController.m - (void)vie

我在将图像加载到UICollectionView时遇到问题。我正在尝试拍摄一张照片,并将其以特定名称保存到Documents文件夹,我希望在照片拍摄取消后,此照片显示在Collection视图中

到目前为止,我的图像保存在documents文件夹中,并自动添加到_stepImagesArray中,但我不知道如何加载这些图像并用它们填充uicollectionview

请帮忙,我的尝试和错误已经有一段时间了:)

StepsCollectionViewController.m

- (void)viewDidLoad
{

[super viewDidLoad];

_stepImagesArray = [[NSMutableArray alloc] init];

}


#pragma mark - UICollectionView settings
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:     (NSInteger)section {
return _stepImagesArray.count;


}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView     cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";


CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];


cell.imageCell.image = [UIImage imageNamed:[_stepImagesArray objectAtIndex:indexPath.row]];




cell.labelCell.text = _stepImagesArray[indexPath.row];

return cell;
}


- (IBAction)takePhoto

{

UIImagePickerController *photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:photoPicker animated:YES completion:NULL];

}


- (void)imagePickerController:(UIImagePickerController *)photoPicker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

UIImage *selectedImage = [info valueForKey:UIImagePickerControllerOriginalImage];
[self.selectedImageView setImage:selectedImage];    


arrayCount = self.stepImagesArray.count;

NSLog(@"array count is: %i",arrayCount);


NSString *jpgImageName = [NSString stringWithFormat:@"Documents/FolderName_%@%i.jpg", passedStepName, arrayCount+1];
NSString *jpgImageNameForArray = [NSString stringWithFormat:@"FolderName_%@%i.jpg", passedStepName, arrayCount+1];



NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent: jpgImageName];

[UIImageJPEGRepresentation(selectedImage, 0.1) writeToFile:jpgPath atomically:YES];

// Let's check to see if files were successfully written...

// Create file manager
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];

// Point to Document directory
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);


[_stepImagesArray addObject:jpgImageNameForArray];

[photoPicker dismissViewControllerAnimated:YES completion:nil];


}
CollectionViewCell.h

@interface CollectionViewCell : UICollectionViewCell

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

@property (weak, nonatomic) IBOutlet UILabel *labelCell;

@end

您遇到了什么错误?uicollectionview为空。不知道如何从documents文件夹加载图像,并使collection视图显示它。