san*_*ndy 8 objective-c .doc ios
是否可以在iphone/iPad中打开word和excel文件而不使用UIwebview?
Aks*_*hay 12
你有两个选择.对于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
}
Run Code Online (Sandbox Code Playgroud)
并按如下方式初始化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];
Run Code Online (Sandbox Code Playgroud)
对于较旧的iOS版本,您可以通过以下方式使用UIDocumentInteractionController.实施委托方法 -
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
return self;
}
Run Code Online (Sandbox Code Playgroud)
初始和显示 -
UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
docController.delegate = self;
[docController presentPreviewAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
谢谢,
阿克沙伊
| 归档时间: |
|
| 查看次数: |
3593 次 |
| 最近记录: |