美文网首页
iOS查看office文档(系统自带)

iOS查看office文档(系统自带)

作者: Devin_明 | 来源:发表于2019-03-20 16:51 被阅读0次

注:在模拟器中可能下载下文件但没内容显示,需要在真机上运行测试使用

1、导入头文件

#import<QuickLook/QuickLook.h>

遵守协议 :QLPreviewControllerDataSource,QLPreviewControllerDelegate

2、   

@property(nonatomic,strong)NSString*deFilePath;  //这个是存到本地的文件地址

例如:

file:///Users/lilianming/Library/Developer/CoreSimulator/Devices/5322EE30-3908-4791-BB13-37FF7272ACF4/data/Containers/Data/Application/851245D6-C482-4397-8585-60392C3F4E64/Documents/20160315180123_8ekihq.xlsx

- (void)quickLookFiles  //初始化 代理 设置当前页 

   QLPreviewController*preView = [[QLPreviewControlleralloc]init];

    preView.dataSource=self;

    preView.delegate=self;

    preView.currentPreviewItemIndex=0;

    [self.navigationControllerpushViewController:preViewanimated:YES];

}

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController*)controller

{

   return1;

}

- (id)previewController:(QLPreviewController*)previewController previewItemAtIndex:(NSInteger)idx{

 return[NSURLURLWithString:_deFilePath];//返回的要是一个URL形式  && 直接返回网址能打开吗?

}

相关文章

网友评论

      本文标题:iOS查看office文档(系统自带)

      本文链接:https://www.haomeiwen.com/subject/vgdtvqtx.html