不使用 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/