在iOS上不使用UIWebview即可打开word,excel和PDF文件 [英] Opening word,excel, and PDF files without using UIWebview on iOS

查看:306
本文介绍了在iOS上不使用UIWebview即可打开word,excel和PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不使用UIWebview的情况下在iPhone/iPad中打开word和excel文件?

Is it possible to open word and excel file in iPhone/iPad without using UIWebview?

推荐答案

您有两个选择.对于iOS 4.0或更高版本,可以使用QLPreviewController.您将需要实现以下两种方法-

You have two options. For iOS 4.0 or later, you can use the QLPreviewController. You will need to implement the following two methods-

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller 
{
  return 1; //assuming your code displays a single file
}

- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index 
{
  return [NSURL fileURLWithPath:path]; //path of the file to be displayed
}

并按如下所示初始化QLPreviewController-

And initialize the QLPreviewController as follows-

QLPreviewController *ql = [[QLPreviewController alloc] init];
 ql.dataSource = self;
 ql.delegate = self;
 ql.currentPreviewItemIndex = 0; //0 because of the assumption that there is only 1 file  
 [self presentModalViewController:ql animated:YES];
 [ql release];

对于较旧的iOS版本,您可以通过以下方式使用UIDocumentInteractionController.实现委托方法-

For older iOS versions, you can use the UIDocumentInteractionController in the following way. Implement the delegate method-

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
 return self;
}

初始化&显示-

Init & display-

    UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
docController.delegate = self;
[docController presentPreviewAnimated:YES];

谢谢

Akshay

这篇关于在iOS上不使用UIWebview即可打开word,excel和PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆