Frederik
Frederik

Reputation: 604

QLPreviewController only shows a single file

I am using a QLPreviewController to display a set of files. However, it only shows the first one and I can't seem to swipe or do anything to show the second. What am I doing wrong? Do I have to set it manually? If so - how would I go about doing that?

This is from my AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // normal viewcontroller init here 

    [self showPreview] ;

    return YES;
}

NSArray* documents ;
QLPreviewController* preview ;

- (void) showPreview
{
    documents = [[NSArray alloc] initWithObjects: @"photo" , @"photo2" , nil ] ;

    preview = [[QLPreviewController alloc] init];
    preview.dataSource = self;
    preview.delegate = self;

    preview.view.frame = [[UIScreen mainScreen] bounds];
    //save a reference to the preview controller in an ivar
    //  self.previewController = preview;
    //refresh the preview controller
    [preview reloadData];
    [[preview view] setNeedsLayout];
    [[preview view] setNeedsDisplay];
    [preview refreshCurrentPreviewItem];
    preview.view.userInteractionEnabled = YES;

    //add it  
    [self.viewController.view addSubview:preview.view];
}

I also declared the two callback functions in the same AppDelegate.m file:

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
{
    NSString* filename = [documents objectAtIndex:index] ;      //  @"photo" ; 
    NSURL* returnURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: filename ofType:@"jpg" ]] ;

    return returnURL ;
}

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
    return [documents count];
}

Upvotes: 1

Views: 2341

Answers (1)

HyBRiD
HyBRiD

Reputation: 708

You are displaying it wrong. QLPreviewController is a UIViewController, which means you basically have 2 ways of displaying it:

  1. Push it into your UINavigationController.
  2. Display it modally (this can be done with or without a UINavigationController - depends if you want a navigation bar).

If you choose option 2 you get "free" navigation arrows to switch between items. For option 1 you need to create the arrows yourself.

This following is taken from the QLPreviewController documentation:

If there is more than one item in the list, a modally-presented (that is, full-screen) controller displays navigation arrows to let the user switch among the items. For a Quick Look preview controller pushed using a navigation controller, you can provide buttons in the navigation bar for moving through the navigation list.

Upvotes: 1

Related Questions