Search code examples
ioscocoa-touchquicklook

How to use QLPreviewController in the Interface Builder?


Is it possible to use the QLPreviewController in the Interface Builder? I am using storyboards and segues, and it would be lovely to also have a representation for the QLPreviewController.


Solution

  • I asked the same question several weeks ago. As far as I know there is no representation for the QuickLook Framework. But it shouldn't be too hard to get this done programmatically.

    I suppose you have an UITableView. Then implement QLPreviewControllerDataSource into your header and the following two methods to your implementation:

    - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller;
    - (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index;
    

    Don't set a segue for the cells and leave the storyboard methods. Instead in the tableView:didSelectRowAtIndexPath: create a new instance of a QLPreviewController and push it onto the stack of the navigation controller.

    PreviewController* previewController = [[PreviewController alloc] init];
    [previewController setDataSource:self];
    [previewController setDelegate:self];
    [previewController setCurrentPreviewItemIndex:indexPath.row];
    [self.navigationController pushViewController:previewController animated:YES];