Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

objective c - Opening word,excel, and PDF files without using UIWebview on iOS

Is it possible to open word and excel file in iPhone/iPad without using UIWebview?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
}

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];

For older iOS versions, you can use the UIDocumentInteractionController in the following way. Implement the delegate method-

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

Init & display-

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

Thanks,

Akshay


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...