0

May I know how to display the latest image first in app document directory using MWPhotoBrowser?

I use below codes to save image in the app document directory and display the images.

- (IBAction)saveButtonPressed:(id)sender
{   
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// Get documents folder
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/abc"];

//Create folder
if (![fileMgr fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];

//Get the current date and time and set as image name
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd_HH:mm:ss";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSString *gmtTime = [dateFormatter stringFromDate:now];
NSLog(@"The Current Time is :%@", gmtTime);

NSData *imageData = UIImageJPEGRepresentation(self.imageTaken, 0.5);
NSString *imgfileName = [NSString stringWithFormat:@"%@%@", gmtTime, @".jpg"];
// File we want to create in the documents directory
NSString *imgfilePath= [dataPath stringByAppendingPathComponent:imgfileName];
// Write the file
[imageData writeToFile:imgfilePath atomically:YES];
}

- (void)selectPhoto
{
self.isCamera = NO;

NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/abc"];
self.photos = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:&error];

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:self.browser];
[self.browser reloadData];
nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:nc animated:YES completion:nil];
}
IPS Brar
  • 346
  • 1
  • 14
Winter
  • 47
  • 1
  • 6

0 Answers0