ios - 在 iOS 上不使用 UIWebview 打开 word、excel 和 PDF 文件

标签 ios objective-c .doc

不使用 UIWebview 可以在 iPhone/iPad 中打开 word 和 excel 文件吗?

最佳答案

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

- (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-

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。实现委托(delegate)方法-

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

初始化&显示-

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

谢谢,

阿克谢

关于ios - 在 iOS 上不使用 UIWebview 打开 word、excel 和 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6983502/

相关文章:

ios - 如何将此文本分配给 iPhone SDK 中的标签

ios - 在 Swift 中从 Core Data 更新静态 UITableViewCell 中的内容

objective-c - 如何使大纲 View 像表格 View 一样可重新排序?

objective-c - 推送应用更新以进行存储,但捆绑ID,配置文件和证书丢失

rstudio - 使用 R markdown 编织 Word .doc 时将表格标题放在顶部

ios - 在 Unity 项目中使用 OpenGL ES 在 iOS 上进行纹理渲染

ios - 以泛型类型数组作为参数的 Swift 编译器错误

ios - 为什么我的 Tableview 数据是空白的?我无法重新加载数据

java - 使用 Apache POI 更新 .docx 文件的页眉