我明白这是一个旧的帖子,但我遇到类似的问题,作为@ user1392687,并希望分享我是如何解决问题的(我从各种目录加载文件,而不仅仅是文档文件夹)。
问题:从一个目录中加载一系列PDF文件,用文件名填充一个表格视图并支持元数据,然后在选择一个单元格后,使用VFR阅读器打开PDF文件。
解决方案:X代码中的文件夹是一个文件夹引用,用于启用内容更新,而无需执行组引用的删除/添加循环。下面的函数用于读取特定文件夹路径的所有内容(URL),然后删除返回的文件路径中包含的所有/任何simlink。事先将URL传递到VRF中以加载PDF文件[url path]用于RFC 1808(未转义)路径。
+ (NSArray *)enumerateContentsOfFolderWithPath:(NSURL *)aFolderPath
{
NSError *error = nil;
NSArray *contentProperties = @[NSURLIsDirectoryKey,
NSURLIsReadableKey,
NSURLCreationDateKey,
NSURLContentAccessDateKey,
NSURLContentModificationDateKey];
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:aFolderPath
includingPropertiesForKeys:contentProperties
options:NSDirectoryEnumerationSkipsHiddenFiles
error:&error];
if (error != nil)
DLog(@"Content enumeration error: %@", error);
NSMutableArray *pdfURLs = [NSMutableArray array];
for (NSURL *item in contents)
{
NSURL *fileURL = [NSURL fileURLWithPath: [item path]];
NSURL *noSimlink = [fileURL URLByResolvingSymlinksInPath];
[pdfURLs addObject: noSimlink];
}
return pdfURLs;
}
填充与文件夹的内容,以及所有支持元数据表视图后,并在触摸一行查看PDF文件的用户,在VRF阅读器是设置如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Other setup code...
NSURL *item = [pdfURLs objectAtIndex:(NSUInteger) indexPath.row];
[self presentPdfViewerForItem: item];
}
- (void)presentPdfViewerForItem:(NSURL *)aItem
{
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
NSString *filePath = [aItem path];
ReaderDocument *document = [ReaderDocument withDocumentFilePath: filePath password:phrase];
if (document != nil) // Must have a valid ReaderDocument object in order to proceed
{
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self;
readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:readerViewController animated:YES completion:nil];
}
}
你能解决这个问题吗?我有同样的问题;无法使用未包含在主包中的文件获取ReaderDocument。就我而言,我正在下载它,然后将它写入Documents目录; ReaderDocument init始终失败。 – wkhatch