-2

私のアプリはpdfを作成します。これは通常のメニューで開いてから表示できますが、アプリでは表示できません。ipadリーダーでプログラムでpdfを開く方法は?

4

1 に答える 1

2

ヘッダーの ViewController でデリゲートを設定する必要があります。

@interface YourViewController : UIViewController <UIDocumentInteractionControllerDelegate>

次に、このメソッドを実装する必要があります。

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

そして、どのpdfを開く必要があるかをキャッチすると:

    NSString *sPathPDF = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"name.pdf"]]; //path example for a local stored pdf
    NSURL *urlPDF = [NSURL fileURLWithPath:sPathPDF];
    UIDocumentInteractionController *dicPDF = [UIDocumentInteractionController interactionControllerWithURL: urlPDF];
    [dicPDF setDelegate:self];
    [dicPDF presentPreviewAnimated: YES];
于 2012-09-25T10:28:41.753 に答える