1

我想实现 QuickLook API 来预览 pdf 文件。我制作了一个基于视图的应用程序,并在 .h 文件中导入 QuickLook/QuickLook.h 。在 .m 文件中,我在 viewDidLoad 中创建了 QLPreviewController 的对象。之后我尝试制作 QLPreviewItem 的对象,但这给出了错误“QLPreviewItem undeclared”。如果可以的话,请帮助我。

谢谢。

4

2 回答 2

4

QLPreviewItem 不是一个类,而是一个协议。您必须使用 NSURL 来填充 API(NSURL 符合 QLPreviewItem)或创建您自己的符合该协议的对象类。

于 2010-12-25T00:51:14.633 回答
2

Your almost there!

the QLPreviewController need a QLPreviewControllerDataSource

implement <QLPreviewControllerDataSource>

and add two functions:

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
    return 1; //number of documents, usually you use a array with document url's
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
{
    return [NSURL fileURLWithPath:@"document.pdf"]; //other documents are supported too
}

Your see that the second method a QLPreviewItem returns (as you see it works with plain URL's too)

I hope I helped you a bit further

于 2011-08-04T11:33:54.410 回答