2013-09-26 115 views
2

我已閱讀有關QLPreviewController在某些條件下不能工作的其他信息。這一個讓我難以承受:QLPreviewController適用於iOS 6;不在iOS 7

RHBlobCollectionRHBlobView是模型/視圖對象,它們分別保存提前高速緩存的集合和單個可顯示文件。

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... 

proof1proof2proof3都返回YES。拉出一個單獨的概念驗證項目,QLPreviewController按照它應該做的。然而,在我的完整應用程序項目中,它可以在iOS 6下運行,但在iOS 7下掛載在「加載...」上。

我的直覺告訴我,它應該與格式錯誤的文件URL有關或路徑,但我的小測試顯示一切都是copasetic。有沒有其他人有這個問題?

回答

1

爲了完整起見,我找到了問題。我實際上使用了NSURL的一個子類,這是一個簡單的事情,它爲人類可讀的文檔標題(previewItemTitle)添加了一個單獨的字符串。當我將事情改回NSURL時,事情開始奏效。醜陋的標題爲一些奇怪的文件名,但至少它們出現。回到繪圖板,瞭解如何處理該問題...

1

我同意 6以下previewItemAtIndex指數> 0 而7指數總是-1無論計數 您能否確認?

+0

當我計算numberOfPreviewItemsInPreviewController中的項數不正確時,我得到了這個問題。 –

+0

@那個傢伙,我證實了這個數字是正確的。 – rsswtmr

+0

@NewDev,不,索引始終是被請求文檔的索引。第一份文件爲0,第二份爲1等。 – rsswtmr

相關問題