(浏览文档)UIDocumentInteractionController打开自己的第三方应用、使用QLPreviewController浏览文档
来源:互联网 发布:淘宝上货怎么上 编辑:程序博客网 时间:2024/05/22 02:02
-(void)openDocumentIn{
}
其中的 documentController.UTI 表示那些类型的文件支持第三方软件打开,此链接里面有各种类型文件对应的数https://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdent
然后delegate里面的方法
- (UIViewController *)documentInteractionContr
{
}
QLPreviewController:
iOS SDK包括了QLPreviewControllerAPI,组件允许用户浏览许多不同的文件类型,如XLS文件,Word文档文件,PDF文件。约翰已创建了一个示例应用程序演示使用QLPreviewController。在示范中,您可以查看几个不同的文件类型,甚至打印(使用无线打印机。)随着一个简短的教程,我们解释实施QLPreviewController的基础步骤,你可以找到约翰的例子::::对于过去的几个月中,我一直花一些时间检查出IOS快看文件预览 -接下来是一个短的应用程序,我写着是为了更熟悉QLPreviewControllerAPI。对于那些不熟悉的读者可以这么看,quick look是一个框架,它提供快速预览的一系列文件类型 -支持的文件包括iWork文档,微软Office,RTF格式,PDF格式,图像,文本文件,并以逗号分隔(CSV)文件。接下来在演示的程序中,我用了三个不同文件类型,.xls/image/ms office /pdf
为应用程序的接口文件如下所示,注意QL数据源的引用,使用的QLPreviewController时,你必须实现此协议QLPreviewControllerDataS
- #import
-
- @interface
TestViewController : UITableViewController ource> - {
-
NSArray *arrayOfDocuments; - }
-
- @end
在本节中,我将展示一个选择适用于设立预览代码。创建表视图和填充相同的代码可以被视为在Xcode项目,你可以从下面的链接下载(如果要学习tableview的使用,可以参考其它的指南)。
初始化代码填入文件名的数组: 这样文件名全在数组了:
- -(id)init
- {
-
if (self = [super init]) -
{ -
arrayOfDocuments = [[NSArray alloc] initWithObjects: -
@"iOSDevTips.png", "Remodel.xls",@ "Core@ ,J2ME Technology.pdf" nil]; -
} -
return self; - }
下面的方法是采用QLPreviewControllerDataS
- -
(NSInteger) numberOfPreviewItemsInPr eviewController: (QLPreviewController *) controller - {
-
return [arrayOfDocuments count]; - }
这种呢,算是question type的events,就是问 文件从什么地方来,NSURL
- -
(id )previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index - {
-
// Break the path into its components (filename and extension) -
NSArray *fileComponents = [[arrayOfDocuments objectAtIndex: index] componentsSeparatedByStr ing:@"."]; -
-
// 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]]; - //这个代码就体现了灵活性,你也可以写成
ofType .pdf -
return [NSURL fileURLWithPath:path]; - }
项目中的其余代码是典型的iPhone/的iOS的东西,创建应用程序委托,委托的UIWindow中添加一个子视图(导航控制器),使窗口可见。我从下面的委托代码,在这里你可以得到更大的图片视图我如何设置此应用程序的视图控制器。
- -
void)applicationDidFinishLaun( ching:(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] initWithRootViewControll er:vc]; -
-
[window addSubview:[nav view]]; -
[window makeKeyAndVisible]; - }
在选中特定行的时候,初始化QLPreviewController:
-
- -
(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 setCurrentPreviewItemInd ex:indexPath.row]; -
-
// Push new viewcontroller, previewing the document -
[[self navigationController] pushViewController:previewer animated:YES]; - }
值得一提的是预览控制器工作时,你有两种不同的选择。首先,你可以推到使用一个UINavigationController对象,你可以看到预览控制器的对象是我做了什么。预览我的应用程序生命在TestViewController这个对象控制器设置为导航控制器的根视图控制器。
第二种方法来显示预览控制器是模态,使用方法presentModalViewControll
- #pragma
mark - - #pragma
mark QLPreviewControllerDataS ource -
- //
Returns the number of items that the preview controller should preview - -
(NSInteger)numberOfPreviewItemsInPr eviewController:(QLPreviewController *)previewController - {
-
return //30//you5; can increase/decrease the this - }
-
- //
returns the item that the preview controller should preview - -
(id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)idx - {
-
return fileURL; - }
-
-
- -
(BOOL)shouldAutorotateToInterf aceOrientation:(UIInterfaceOrientation)interfaceOrientation - {
-
// Return YES for supported orientations -
return (interfaceOrientation == UIInterfaceOrientationPo rtrait); - }
以上就是QLPreviewController的一些delegate,首先是预览页面数目,其次是我需要的URL(NSURL),最后是这个view的支持rotation程度
- (浏览文档)UIDocumentInteractionController打开自己的第三方应用、使用QLPreviewController浏览文档
- iOS指南系列:使用QLPreviewController浏览文档
- 使用第三方APP打开本地文档 (UIDocumentInteractionController)
- UIDocumentInteractionController 第三方应用中打开自己的文件 方法
- UIDocumentInteractionController 第三方应用中打开自己的文件 方法
- 利用UIDocumentInteractionController文档预览以及调用iPhone里第三方相关的app打开文档
- 用第三方程序打开自己应用里的文档
- iOS 第三方应用中打开自己的文件(UIDocumentInteractionController)
- UIDocumentInteractionController的使用之打开和预览文档
- Android端 通过第三方应用打开文档的方式
- UIDocumentInteractionController 预览和打开文档
- iOS UIDocumentInteractionController 设置第三方打开方式的 参数详解
- UIDocumentInteractionController浏览文件
- iOS UIDocumentInteractionController 第三方打开详解
- Project文档浏览
- android读取word文档的方法:一,第三方应用打开
- 之利用UIDocumentInteractionController打开和预览文档
- 文档,影音的的在线浏览
- 蓝桥杯 结果填空 奇怪的比赛 dfs
- View 绘制流程
- Matlab中的inf
- 数据仓库介绍(四) - 逻辑数据模型
- 依赖注入
- (浏览文档)UIDocumentInteractionController打开自己的第三方应用、使用QLPreviewController浏览文档
- django启动
- 微信开发-验证服务器
- Android—eclipse长时间停在calculating requirements and dependencies解决办法
- View 事件传递
- 线段树扫描线(感觉不错就转载了..)
- 使用python的机器学习算法包scikit-learn
- LeetCode Remove Duplicates from Sorted Array II
- Posix多线程笔记(三)—线程属性(2)