我已閱讀有關QLPreviewController
在某些條件下不能工作的其他信息。這一個讓我難以承受:QLPreviewController適用於iOS 6;不在iOS 7
RHBlobCollection
和RHBlobView
是模型/視圖對象,它們分別保存提前高速緩存的集合和單個可顯示文件。
RHBlobView.m:
- (IBAction) handleBlobTap:(UITapGestureRecognizer *)sender
{
QLPreviewController *previewController = [[QLPreviewController alloc] init];
// view tag is index in array of blobs
[previewController setCurrentPreviewItemIndex:self.tag];
// blobContainer is type RHBlobCollection
[previewController setDataSource:self.blobContainer];
UINavigationController *navController = (UINavigationController *)[[[[UIApplication sharedApplication] delegate] window] rootViewController];
[navController pushViewController:previewController animated:YES];
}
RHBlobCollection.m:
- (NSInteger) numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return [self.blobs count];
}
- (id <QLPreviewItem>) previewController:(QLPreviewController *)controller
previewItemAtIndex:(NSInteger)index
{
RHBlobView *blob = self.blobs[(NSUInteger) index];
NSURL *fileURL = [RHCacheManager cachedFileURLForFilename:blob.filename withKey:blob.blobID];
// URL proper?
BOOL __unused proof1 = [fileURL isFileURL];
// QLPreviewController can stomach it?
BOOL __unused proof2 = [QLPreviewController canPreviewItem:fileURL];
// Cached file actually exists?
NSString *proof3path = [[fileURL resourceSpecifier] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
BOOL __unused proof3 = [[NSFileManager defaultManager] fileExistsAtPath:proof3path];
// Unless we're dealing with thumbnails, we're done. Return the URL of the resource.
if (! [blob hasThumbnails])
{
return fileURL;
}
// Process thumbnails into .pdf file for display...
proof1
,proof2
和proof3
都返回YES
。拉出一個單獨的概念驗證項目,QLPreviewController
按照它應該做的。然而,在我的完整應用程序項目中,它可以在iOS 6下運行,但在iOS 7下掛載在「加載...」上。
我的直覺告訴我,它應該與格式錯誤的文件URL有關或路徑,但我的小測試顯示一切都是copasetic。有沒有其他人有這個問題?
當我計算numberOfPreviewItemsInPreviewController中的項數不正確時,我得到了這個問題。 –
@那個傢伙,我證實了這個數字是正確的。 – rsswtmr
@NewDev,不,索引始終是被請求文檔的索引。第一份文件爲0,第二份爲1等。 – rsswtmr