6

メインメニューに通常のUIButtonがあり、現在UIViewControllerを起動しています。対応する.mファイルの内容は次のとおりです。

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    documentPath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"pdf"];
    NSURL *targetURL = [NSURL fileURLWithPath:documentPath];

    document = [UIDocumentInteractionController interactionControllerWithURL: targetURL];
    document.delegate = self;
    [document retain];

    return self;
}

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

-(void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
    [document autorelease];
}

-(void)viewDidLoad
{
    [super viewDidLoad];

    [document presentPreviewAnimated: YES]; // ** CRASH **
}

-(void)viewDidUnload
{
    [super viewDidUnload];
}

-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

-(void)dealloc
{
    [super dealloc];
}

PDFファイルは期待どおりに読み込まれますが、[完了]ボタンを押すとドキュメントが閉じ、空白のUIViewControllerを見つめたままになります-おそらく期待どおりです。しかし、ナビゲーションの「戻る」ボタンを押すと、アプリがクラッシュし、viewDidLoadメソッド内で不正なアクセスエラーが発生します。ここで、presentPreviewAnimatedの呼び出しが見つかります。

誰か見ていただければ幸いです。

(ところで、このView Controllerの作成時にはNIBファイルはありません。はい、これ自体は間違っています)

4

1 に答える 1

1

ビューの作成中にこれを行うことが問題であるかどうか疑問に思います。そのため、ユーザーがドキュメントプレビューを閉じると、不完全な形式のUIViewに戻ります。したがって、おそらく最初にビューをビルドしてロードしてから、viewDidAppearからUIDocumentを実行しますか?

于 2011-05-27T15:55:08.557 に答える