Change the init method below.
-(id)init { if (self = [super init]) { // arrayOfDocuments = [[NSArray alloc] initWithObjects: // @"iOSDevTips.png", @"Remodel.xls", @"Core J2ME Technology.pdf", nil]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *docPath = [paths lastObject]; NSArray *docArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docPath error:nil]; arrayOfDocuments = [[NSArray alloc] initWithArray:docArray]; } return self; }
Add this new method.
-(NSString*)documentDirectoryPathForResource:(NSString*)aFileName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *fullPath = [[paths lastObject] stringByAppendingPathComponent:aFileName]; return fullPath; }
And replace your method with my method
- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
The code itself. Just create an array of all the documents that are in your document directory. And after that, use this array to create the path and specify the URL of this path for the QLPreviewController
source share