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?)
Asked
Active
Viewed 1,454 times
1 Answers
2
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.

jscs
- 63,694
- 13
- 151
- 195
-
It seems a lot of fuss just preview something. And I don't understand the number of items/index. Surely theres only one thing display, unlike a table view where there are many rows. – Jonathan. Apr 22 '11 at 17:26
-
The panel allows flipping through a list of previews. You can return whatever you want from these methods; return 1 from `numberOfPreviewItems...` and then whatever single item you like from `previewPanel:previewItem...` – jscs Apr 22 '11 at 17:34
-
Except the returned preview item has to follow `QLPreviewItem` and the item has to be an URL, when I just have the image as an NSImage. – Jonathan. Apr 22 '11 at 17:57
-
@Jonathan Right...the preview panel is for files, not objects in memory. – jscs Apr 22 '11 at 18:02
-
I've now changed how the app works to avoid this, but thanks anyway – Jonathan. Apr 22 '11 at 18:20