Xcode - view / delete files from NSDocumentDirectory

My application has a Browse button with these codes that allows the user to view the iPad’s photo gallery, select a photo, and store it in the application using NSDocumentDirectory.

- (IBAction) BrowsePhoto:(id)sender { UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController]; [popover setPopoverContentSize:CGSizeMake(320,320)]; [popover presentPopoverFromRect:CGRectMake(200,200,-100,-100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; self.popoverController = popover; [imagePickerController release]; } - (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:@"SavedImage.png"]; UIImage *image = imageView.image; NSData *imageData = UIImagePNGRepresentation(image); [imageData writeToFile:savedImagePath atomically:NO]; } 

Now I want to enable the "Show" button, which displays all the photos from NSDocumentDirectory in a new view. Thinking about displaying it in thumbnails, as well as playing the image, a pop-up window will appear asking him to confirm whether he wants to delete the selected photo. If so, the photo will be deleted from NSDocumentDirectory.

Can this be done? If so, consider how to do it and share some sample codes? I am completely lost because I am still new to programming.

+4
source share
1 answer

Everything you need to do with files is implemented in the NSFileManager system class.

This is not difficult. Try reading the documentation and some Google examples. There are many, for example. http://www.theappcodeblog.com/2011/04/04/nsfilemanager-tutorial-create-read-and-delete-a-file/

+1
source

All Articles