是否可以在iphone/iPad中打开word和excel文件而不使用UIwebview?
你有两个选择.对于iOS 4.0或更高版本,您可以使用QLPreviewController
.您需要实施以下两种方法 -
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller { return 1; //assuming your code displays a single file } - (id)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.实施委托方法 -
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { return self; }
初始和显示 -
UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; docController.delegate = self; [docController presentPreviewAnimated:YES];
谢谢,
阿克沙伊