我的主菜单上有一个常规的 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 的调用。
如果有人可以请看一下,我将不胜感激。
(顺便说一句,创建此视图控制器时没有NIB文件。是的,这本身就是错误的)