Search code examples
objective-cmacosquicklook

How to use QLPreviewPanel?


I have an app which can download images and text, I want to use the QLPreviewPanel to give a preview of this. However the delegate and datasource implementation has me confused. I just want to pass an image or string and have it displayed? (is QLPreviewPanel even the right thing to use here?)


Solution

  • There's not much to it. Take a look at Apple's sample project Quick Look Downloader; the file MyDocument.m has the data source and delegate methods.

    The data source methods are just like table view data source methods:

    - (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel
    {
        return [myCollectionOfItems count];
    }
    
    - (id <QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index
    {
        return [myCollectionOfItems objectAtIndex:index];
    }
    

    You can skip implementing a delegate if you don't need to customize the behavior of the panel.