http://blog.sina.com.cn/s/blog_7fa6b06f0101dh1b.html
//得到文件存放路径
-(NSString*)GetKnowledgeFileFullPath:(NSString*)FileName
{
@try {
// 文件存放目录
NSString *pngDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSError *err;
[fileMgr createDirectoryAtPath:pngDir withIntermediateDirectories:YES attributes:nil error:&err];
NSString *FileFullPath = [pngDir stringByAppendingPathComponent:FileName];
return FileFullPath;
}
@catch (NSException *exception) {
return nil;
}
@finally {
}
}
//===========================================================================
// 预览指定的文件
// (支持iWork documents、Microsoft Office documents (Office ‘97 and newer)、Rich Text Format
// (RTF) documents、PDF files、Images、Text files whose uniform type identifier (UTI) conforms
// to the public.text typ、Comma-separated value (csv) files)
//===========================================================================
- (void)PreviewKnowledge:(NSString*)KnowledgeFullPath
{
@try {
QLPreviewController *previewoCntroller = [[QLPreviewController alloc] init];
BZPreviewDataSource *dataSource = [[BZPreviewDataSource alloc]init];
dataSource.path = [[NSString alloc] initWithString:KnowledgeFullPath];
previewoCntroller.dataSource = dataSource;
[previewoCntroller setTitle:@"test"];
previewoCntroller.navigationItem.rightBarButtonItem=nil;
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 5.0){
//此函数是5.0之后的函数。
[self presentViewController:previewoCntroller animated:YES completion:nil];
}
else {
//[self presentModalViewController:previewoCntroller animated:YES];
[self.navigationController pushViewController:previewoCntroller animated:YES];
}
}
@catch (NSException *exception) {
[Logger WriteLog:__FILE__ funcName:__func__ lineNum:__LINE__ exceptionObj:exception textInf:NULL];
}
@finally {
}
}
#import <Foundation/Foundation.h>
#import <QuickLook/QuickLook.h>
@interface BZPreviewDataSource : NSObject<QLPreviewControllerDataSource>
@property (nonatomic, retain) NSString *path;
@end
//类的实现
#import "BZPreviewDataSource.h"
@implementation BZPreviewDataSource
@synthesize path = _path;
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 1;
}
- (id <<span style="color: #7340a3">QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:_path];
}
@end