UIDocumentInteractionController在退出时崩溃 [英] UIDocumentInteractionController crashing upon exit

查看:126
本文介绍了UIDocumentInteractionController在退出时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主菜单上有一个常规的UIButton,目前正在启动一个UIViewController;相应的.m文件的内容如下:

I have a regular UIButton on my main menu that currently launches a UIViewController; the contents of the corresponding .m file is as follows:

-(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的调用。

My pdf file loads as expected, however when I hit the "done" button the document closes and I am left staring at my blank UIViewController - arguably as expected. But if I hit the navigation "back" button then the app crashes with a bad access error inside my viewDidLoad method, where the call to presentPreviewAnimated is found.

如果有人可以请看一下,我将非常感激。

If somebody could please take a look, I would be most grateful.

(顺便说一下,创建这个视图控制器时没有NIB文件。是的,这本身就错了)

(btw, there is no NIB file when this view controller is created. Yes, this in itself is wrong)

推荐答案

我想知道问题是否是你在视图创建过程中这样做的。因此,当用户关闭文档预览时,它将返回到未完全形成的UIView。那么可能首先构建并加载视图然后从viewDidAppear执行UIDocument?

I am wondering whether the issue is that you do this during view creation. So that when the user closes the document preview, it gets back to an incompletely formed UIView. So perhaps first build and load the view and then do UIDocument from viewDidAppear ?

这篇关于UIDocumentInteractionController在退出时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆