iOS文档预览功能教程
ios 4 sdk中支技文档的预览功能,何为预览?就是你打印文件时的预览功能。其用到quicklook.framework,它支持的文档格式有: iWork documents, Microsoft Office, Rich Text Format, PDF, images, text files and comma-separated (csv) files.
今天show一个demo,展示其用法:
第一步:创建一个基于view的工程,并加入quicklook.framewrok
第二步:修改Controller的头文件如下:
- #import <QuickLook/QuickLook.h>
- @interface TestViewController : UITableViewController <QLPreviewControllerDataSource>
- {
- NSArray *arrayOfDocuments;
- }
- @end
修改 controller执行文件如下
- #import "TestViewController.h"
- @implementation TestViewController
- #pragma mark -
- #pragma mark Initialization
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- -(id)init
- {
- if (self = [super init])
- {
- arrayOfDocuments = [[NSArray alloc] initWithObjects:
- @"iOSDevTips.png", @"Remodel.xls", @"Core J2ME Technology.pdf", nil];
- }
- return self;
- }
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- - (void)loadView
- {
- [super loadView];
- [self setTitle:@"Files Available for Preview"];
- }
- #pragma mark -
- #pragma mark Table Management
- // Customize the number of sections in the table view.
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [arrayOfDocuments count];
- }
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"tableRow";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil)
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- // ???
- [[cell textLabel] setText:[arrayOfDocuments objectAtIndex:indexPath.row]];
- [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
- return cell;
- }
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // When user taps a row, create the preview controller
- QLPreviewController *previewer = [[[QLPreviewController alloc] init] autorelease];
- // Set data source
- [previewer setDataSource:self];
- // Which item to preview
- [previewer setCurrentPreviewItemIndex:indexPath.row];
- // Push new viewcontroller, previewing the document
- [[self navigationController] pushViewController:previewer animated:YES];
- }
- #pragma mark -
- #pragma mark Preview Controller
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
- {
- return [arrayOfDocuments count];
- }
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- - (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
- {
- // Break the path into it's components (filename and extension)
- NSArray *fileComponents = [[arrayOfDocuments objectAtIndex: index] componentsSeparatedByString:@"."];
- // Use the filename (index 0) and the extension (index 1) to get path
- NSString *path = [[NSBundle mainBundle] pathForResource:[fileComponents objectAtIndex:0] ofType:[fileComponents objectAtIndex:1]];
- return [NSURL fileURLWithPath:path];
- }
- #pragma mark -
- #pragma mark Cleanup
- /*---------------------------------------------------------------------------
- *
- *--------------------------------------------------------------------------*/
- - (void)dealloc
- {
- // Free up all the documents
- [arrayOfDocuments release];
- [super dealloc];
- }
- @end
修改Appdelegate如下
- - (void)applicationDidFinishLaunching:(UIApplication *)application
- {
- // Create and initialize the window
- window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Create test view controller
- vc = [[TestViewController alloc] init];
- // Create navigation controller
- nav = [[UINavigationController alloc] initWithRootViewController:vc];
- [window addSubview:[nav view]];
- [window makeKeyAndVisible];
- }
所要的资源文件可以源码中找到。
iOS文档预览功能教程的更多相关文章
- 一文带你玩转对象存储COS文档预览
随着"互联网+"的发展,各行各业纷纷"去纸化",商务合同.会议纪要.组织公文.商品图片.培训视频.学习课件.随堂讲义等电子文档无处不在.而要查看文档一般需要先下 ...
- 秒级接入、效果满分的文档预览方案——COS文档预览
一.导语 说起 Microsoft Office 办公三件套,想必大家都不会陌生,社畜日常的工作或者生活中,多多少少遇到过这种情况: 本地创建的文档换一台电脑打开,就出现了字体丢失.排版混乱的情况 ...
- 在线文档预览方案-office web apps续篇
上一篇在线文档预览方案-office web apps发布后收到很多网友的留言提问,所以准备再写一篇,一来介绍一下域控服务器安装,总结一下大家问的多的问题,二来宣传预览服务安装与技术支持的事情. 阅读 ...
- 在线文档预览方案-office web apps
最近在做项目时,要在手机端实现在线文档预览的功能.于是百度了一下实现方案,大致是将文档转换成pdf,然后在通过插件实现预览.这些方案没有具体实现代码,也没有在线预览的地址,再加上项目时间紧迫.只能考虑 ...
- [转载]在线文档预览方案-Office Web Apps
最近在做项目时,要在手机端实现在线文档预览的功能.于是百度了一下实现方案,大致是将文档转换成pdf,然后在通过插件实现预览.这些方案没有具体实现代码,也没有在线预览的地址,再加上项目时间紧迫.只能考虑 ...
- 微软office web apps 服务器搭建之在线文档预览(一)
office web apps安装 系统要求为Windows Server 2012, 注意:转换文档需要两台服务器,一台为转换server,另外一台为域控server.(至于为什么要两台,这个请自行 ...
- 使用OpenOffice实现文档预览
概述 使用OpenOffice将 office文档转为pdf,然后再将pdf转为图片,实现文档预览的功能. 依赖组件 OpenOffice.org或者LibreOffice JODConverter ...
- 微软office web apps 服务器搭建之在线文档预览(二)
上一篇文章已经介绍了整个安装过程了.只要在浏览器中输入文档转换server的ip,会自动跳转,出现如下页面. 那么就可以实现本地文档预览了,你可以试试.(注意:是本地哦,路径不要写错,类似“\\fil ...
- 解决officeOnline文档预览服务器只能域名提交的限制Redirect
此项目是解决officeOnline文档预览只能用域名提交的限制 http://officeOnline文档预览域名或IP/op/generate.aspx // 微软原生页面 创建链接后会生成全屏预 ...
随机推荐
- javascript 获取焦点和失去焦点事件
利用传参的方式提高方法的复用性 这里涉及到JavaScript的字符串拼接操作 </tr> <<tr height="40px"> <td> ...
- hdu 3074(线段树)
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- SSRS的配置
SSRS是微软的报表服务管理器,本文讲述SSRS的配置:邮件和凭证. 一,配置SMTP 在报表服务配置管理器(Reporting Service Configuration Manager)中配置邮件 ...
- Oracle 查看表存储内存
--分配表的物理存储1 select segment_name, bytes from user_segments where segment_type = 'TABLE'; From User_Ex ...
- CodeForces 702B Powers of Two【二分/lower_bound找多少个数/给出一个数组 求出ai + aj等于2的幂的数对个数】
B. Powers of Two You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, ...
- NanoPC-T3 64位裸机编程 —— 启动和运行状态切换
参考: https://github.com/metro94/s5p6818_spl https://github.com/trebisky/Fire3/tree/master/Boot_NSIH h ...
- ELK最佳实践
1.ELK最佳实践解析 a.用户通过nginx或haproxy访问ELK日志统计平台,IP地址为keepalived的vip地址; b.nginx将请求转发到kibana; c.kibana到es获取 ...
- bzoj 5092: [Lydsy1711月赛]分割序列
5092: [Lydsy1711月赛]分割序列 Time Limit: 5 Sec Memory Limit: 256 MBSubmit: 219 Solved: 100[Submit][Stat ...
- 【svn】idea上svn 忽略文件不提交
可以自己新建一个更改文件列表,名字叫忽略 这样 你就可以 单纯的 管理剩余的默认文件了 ======================================================== ...
- Weblogic多数据源(Multi Data Sources)应用实践
原创 2012年03月29日 10:55:28 标签: weblogic / 数据库 / 负载均衡 / 数据中心 / jdbc / 应用服务器 大型系统在进行数据库部署时,常常会分为主数据应用中心 ...