本文介绍了iOS - QuickLook - 如何在没有UIScrollView的情况下在QuickLook中打开对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出我使用QuickLook在不使用UITableView的情况下打开(最好但不一定是pdf)文件的资源吗?



我有这个例子使用QuickLook但它使用了我需要远离的列表视图。



解决方案

我不确定您打算如何设计UI以打开文件。我用了几种不同的方式,所以我会抛出一些想法。 UITableView是大量文件的理想选择。通用滚动视图也可用于大量文件。我已经为仅生成一个或两个文件的应用程序使用了警报视图。您还可以使用带有iPad Mail应用程序等文档图标的视图。要获取文档图标,请使用 UIDocumentInteractionController 。 WWDC 2010 DocInteraction示例代码深入介绍了如何使用 UIDocumentInteractionController



至于打开文件, Quick Look框架使这一切变得简单。一个简单的,独立的解决方案是子类 QLPreviewController 。然后,您的子类需要符合 QLPreviewControllerDataSource 协议以及可选的 QLPreviewControllerDelegate 协议。接下来,传递一个指向您的文件的NSURL数组。您可以通过初始化程序(如 -initWithFiles:(NSArray *)文件)或通过setter执行此操作。从这里开始, -previewController:previewItemAtIndex:只需索引到数组中即可获得要显示的相应文件。 -numberOfPreviewItemsInPreviewController:只需要返回数组的大小。完成此课程后,您可以使用任何您喜欢的UI设计来推送此视图或以模态方式呈现它。



希望这比我读过的教程更清晰。



编辑:



我已经向Github发布了一些可能对您有所帮助的代码。我已经创建了一个,如上所述。我还发布了一个直接使用 QLPreviewController 的。 / p>

Could anyone point me towards a resource which uses QuickLook to open a (preferably but not necessarily a pdf) file without using a UITableView?

I do have this example of using QuickLook but it uses a listview which I need to get away from.

http://robsprogramknowledge.blogspot.com/2011/02/quick-look-for-ios_21.html

解决方案

I'm not sure how you plan to design your UI to open a file. I've used a few different ways, so I'll toss out some ideas. A UITableView is ideal for large amounts of files. A generic scroll view can also be used for a large number of files. I've used an alert view for an app that only generates one or two files. You could also use a view with document icons like the iPad Mail app. To get the document icons, use UIDocumentInteractionController. The WWDC 2010 DocInteraction sample code goes in great depth with how to use UIDocumentInteractionController.

As for opening the file, the Quick Look framework makes that easy. A simple, self-contained solution is to subclass QLPreviewController. Then, your subclass needs to conform to the QLPreviewControllerDataSource protocol and optionally the QLPreviewControllerDelegate protocol. Next, pass it an array of NSURLs pointing to your files. You can do this either through an initializer like -initWithFiles:(NSArray *)files or through a setter. From here, -previewController:previewItemAtIndex: just needs to index into the array to get the appropriate file to show. -numberOfPreviewItemsInPreviewController: just needs to return the size of the array. Once you have this class finished, you can use any UI design you like to push this view or present it modally.

Hopefully this is more clear than my tutorial you've been reading.

EDIT:

I have posted some code to Github that may help you. I have created a file previewer class as described above. I also posted a demo app that directly uses a QLPreviewController.

这篇关于iOS - QuickLook - 如何在没有UIScrollView的情况下在QuickLook中打开对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 03:41