0
votes

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];
}
other option is just set your browser current photo index at last or your leatest image index .Himanshu Moradiya
[Browser setCurrentIndex : ] // just set your latest photo array index and checkHimanshu Moradiya
@HimanshuMoradiya i used this but it fails to show the latest photoWinter
i did not find any array value in your snapcode . so add array in your code so i give you suggestionHimanshu Moradiya
@Anbu.Karthik Thank you. I have added [self.browser reloadData]; and it is working. =)Winter