現在、これらのコードを使用して画像を NSDocumentDirectory に保存しています。私はこのカウンターを命名規則として使用しています。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo
{
[self.popoverController dismissPopoverAnimated:YES];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.png", counter]];
UIImage *image = imageView.image;
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
}
ループを使用してすべてを取得する方が簡単なので、この方法を使用します。NSDocumentDirectory からすべての画像を取得して、別のビューで表示できるようにしたいと考えています。次のコードは、それらを取得する方法を示しています。
-(NSMutableArray *)GetImage:(NSMutableArray *)arrayImgNames
{
NSMutableArray *tempArray;
for(int i=0;i<[arrayImgNames count]; i++)
{
NSArray *paths1 = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths1 objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent: [arrayImgNames objectAtIndex:i]];
[tempArray addObject:[[UIImage alloc] initWithContentsOfFile:filePath]];
return tempArray;
}
}
ただし、画像の命名規則としてカウンターを使用したくありません。それらに適切な名前を使用したいのですが、そうすると、すべての画像を取得する方法を変更する必要があります。
私が言及したこの方法以外に、すべての画像を取得できる他の方法はありますか?