iOS - QuickLook - 如何在没有 UIScrollView 的情况下在 QuickLook 中打开对象
谁能向我指出一个使用 QuickLook 打开(最好但不一定是 pdf)文件而不使用 UITableView 的资源?
我确实有使用 QuickLook 的示例,但它使用了我需要摆脱的列表视图。
http://robsprogramknowledge.blogspot.com/2011/02/quick -查找-ios_21.html
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您打算如何设计打开文件的用户界面。我使用了几种不同的方法,所以我会提出一些想法。 UITableView 非常适合处理大量文件。通用滚动视图也可用于大量文件。我对仅生成一两个文件的应用程序使用了警报视图。您还可以使用带有文档图标的视图,例如 iPad Mail 应用程序。要获取文档图标,请使用 UIDocumentInteractionController。 WWDC 2010 DocInteraction 示例代码深入介绍了如何使用
UIDocumentInteractionController
。至于打开文件,Quick Look 框架使这一切变得简单。一个简单、独立的解决方案是子类化
QLPreviewController
。然后,您的子类需要遵守QLPreviewControllerDataSource
协议以及可选的QLPreviewControllerDelegate
协议。接下来,向其传递一个指向您的文件的 NSURL 数组。您可以通过像-initWithFiles:(NSArray *)files
这样的初始化程序或通过 setter 来完成此操作。从这里开始,-previewController:previewItemAtIndex:
只需要索引到数组即可获取要显示的适当文件。-numberOfPreviewItemsInPreviewController:
只需返回数组的大小。完成此类后,您可以使用任何您喜欢的 UI 设计来推送此视图或以模态方式呈现它。希望这比您正在阅读的我的教程更清晰。
编辑:
我已经在 Github 上发布了一些代码,可能会对您有所帮助。我已经创建了一个 文件预览器类 如上所述。我还发布了一个直接使用
QLPreviewController
的 演示应用。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 useUIDocumentInteractionController
.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 theQLPreviewControllerDataSource
protocol and optionally theQLPreviewControllerDelegate
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
.