我明白這是一箇舊的帖子,但我遇到類似的問題,作爲@ 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