Change your init method to 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
{
// Break the path into it's components (filename and extension)
NSString *path = [self documentDirectoryPathForResource:arrayOfDocuments[index]];
return [NSURL fileURLWithPath:path];
}
Code is self explanatory. Just create the array of all the documents that are in your document directory. And after that use that array to create the path and provide URL of that path to QLPreviewController