iOS 利用QuickLook查看PDF、WORD、PPT、xlsx
来源:互联网 发布:少儿学钢琴软件 编辑:程序博客网 时间:2024/05/23 19:26
代码下载:http://download.csdn.net/detail/qqmcy/7059831
这个我们学习iOS的QuickLook框架实现很简单,如下:
ViewController.h
#import <UIKit/UIKit.h>#import <QuickLook/QuickLook.h>@interface ViewController : UIViewController<QLPreviewControllerDataSource,QLPreviewControllerDelegate,UIDocumentInteractionControllerDelegate>@property (strong , nonatomic) QLPreviewController *previewController;@end
ViewController.m
//// ViewController.m// QuickLook例子//// Created by 杜甲 on 14-3-18.// Copyright (c) 2014年 杜甲. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (strong , nonatomic) NSArray* m_dirArray;@property (strong , nonatomic) UIDocumentInteractionController* m_docInteractionController;@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory NSString* pathppt = [[NSBundle mainBundle] pathForResource:@"C" ofType:@"pdf"]; NSData* pptData = [NSData dataWithContentsOfFile:pathppt]; NSString* filePath = [documentsPath stringByAppendingPathComponent:@"C1.pdf"]; [pptData writeToFile:filePath atomically:YES]; NSFileManager* fileManager = [NSFileManager defaultManager]; self.m_dirArray = [NSArray array]; self.m_dirArray = [fileManager contentsOfDirectoryAtPath:documentsPath error:Nil]; NSLog(@"%@",self.m_dirArray); self.view.backgroundColor = [UIColor redColor]; self.previewController = [[QLPreviewController alloc] init]; //self.previewController.view.frame = CGRectMake(0, 0, 320, 568); self.previewController.view.backgroundColor = [UIColor grayColor]; self.previewController.dataSource = self; self.previewController.delegate = self; // start previewing the document at the current section index self.previewController.currentPreviewItemIndex = 0;//indexPath.row; [self presentViewController:self.previewController animated:YES completion:^{ [self.view addSubview:self.previewController.view]; }]; [self.view addSubview:self.previewController.view];}#pragma mark - QLPreviewControllerDataSource// Returns the number of items that the preview controller should preview- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController{return [self.m_dirArray count];//[self.dirArray count];}- (void)previewControllerDidDismiss:(QLPreviewController *)controller{ // if the preview dismissed (done button touched), use this method to post-process previews}// returns the item that the preview controller should preview- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)idx{NSURL* fileURL = nil; NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentDir = [documentPaths objectAtIndex:0]; NSString* path1 = [self.m_dirArray objectAtIndex:idx]; NSString* path = [documentDir stringByAppendingPathComponent:path1]; fileURL = [NSURL fileURLWithPath:path]; return fileURL;}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- iOS 利用QuickLook查看PDF、WORD、PPT、xlsx
- Flex 在线查看word,pdf,ppt等文档
- word excel ppt jpg pdf 在网站上查看
- 利用FlexPaper实现Word、PPT、PDF在线浏览
- iOS上---预览本地ppt,word ,excel,pdf文件
- POI pdf ppt word excel
- Asp.net MVC 利用(aspose+pdfobject.js) 实现在线预览word、excel、ppt、pdf文件
- Word,PDF,PPT,TXT的转换
- c# word ppt excel转pdf
- c# word ppt excel转pdf
- PPT 、word 、pdf、 txt 格式转换
- java实现word,ppt,excel转pdf
- C#实现 word、pdf、ppt 转为图片
- C#实现 word、pdf、ppt 转为图片
- 常见word,excel,ppt 转pdf
- MFC 打开word、ppt、pdf文件方法
- winform 调用进程打开word pdf ppt
- Android上展示word、excel、pdf、ppt~
- zoj 3329 One Person Game(概率dp)
- hdu 1086 线段相交
- 我的爱阿信
- 第三周作业-循环与判断语句
- VC++定时器的运用
- iOS 利用QuickLook查看PDF、WORD、PPT、xlsx
- Java发送手机短信
- C++注释规范
- PHP中忽略notice
- Py 数据库操作
- Android小技巧(一):实现捕获应用的运行时异常
- 快速用VLC的SDK开发RTSP流教程
- IE屏蔽鼠标右键、禁止复制粘贴等功
- U盘文件乱码还能恢复吗