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

问题描述

是否可以在iphone / iPad中打开word和excel文件而不使用UIwebview?

Is it possible to open word and excel file in iphone/iPad with out 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&显示 -

Init & display-

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

谢谢,

Akshay

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

08-31 07:14