I have written an app that allows the user to take photos which are stored in an NSArray
and which are then saved in the Documents directory
. When they are reloaded the pictures are stored in an UITableView
- note only one photo is currently loaded due to problem 1.
I have two problems:
1 - This works but only for one photo as I need to be able work out how many photos have been stored.
2 - When I reload the data and put into an UIImageView
the rotation of the photos is incorrect. Landscape photos are upside down and portrait photos are landscape.
Any help with either of these issues greatly appreciated.
Saving the photos
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
for (int i=0;i<photoCount;i++)
{
UIImage *image = [photos objectAtIndex:i];
NSString *savePicturePath = [saveFolderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"image_%d",i]];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savePicturePath atomically:NO];
}
Retrieving the photos
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getPicPath = [documentsDirectory stringByAppendingPathComponent:@"image_0"];
NSData *picData = [[NSFileManager defaultManager] contentsAtPath:getPicPath];
UIImage *loadedImage = [UIImage imageWithData:picData];
[photos addObject:loadedImage];
[self.tableView reloadData];
Adding image to table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"photoCell"];
UIImage *currentImage = [self.photos objectAtIndex:indexPath.row];
cell.imageView.image = currentImage;
return cell;
}