我的主菜单上有一个常规的 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 文件。是的,这本身就是错误的)
最佳答案
我想知道问题是否出在您在 View 创建期间执行此操作。这样当用户关闭文档预览时,它又回到了一个未完全形成的 UIView。因此,也许首先构建并加载 View ,然后从 viewDidAppear 执行 UIDocument ?
关于iphone - UIDocumentInteractionController 在退出时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6152764/