Reputation: 1816
I've reviewed other posts regarding QLPreviewController
not working under certain conditions. This one has me stymied:
RHBlobCollection
and RHBlobView
are model/view objects that respectively hold the collection of, and the individual displayable files, cached ahead of time.
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
and proof3
all return YES
. Pulled out into a separate proof-of-concept project, QLPreviewController
does as it's supposed to. In my full app project, though, it works under iOS 6 but hangs on "Loading..." with a spinner under iOS 7.
My gut tells me that it should have something to do with a malformed file URL or path, but my little tests show everything is copasetic. Has anyone else had a problem with this?
Upvotes: 2
Views: 1221
Reputation: 1816
For sake of completeness, I found the issue. I was actually using a subclass of NSURL
, a simple affair that just added a separate string for the human-readable document title (previewItemTitle
). When I changed things back to NSURL
, things started working. Ugly titles for some weird filenames, but at least they appear. Back to the drawing board for how to handle that problem...
Upvotes: 1
Reputation: 257
I would agree Under 6 previewItemAtIndex index is > 0 while with 7 index is Always -1 no matter the count Can you confirm ?
Upvotes: 1