メインメニューに通常の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ファイルはありません。はい、これ自体は間違っています)