我已经查看了有关QLPreviewController
在某些条件下不工作的其他帖子。这个让我受阻:
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。有没有其他人有这个问题?