UIDocumentInteractionController在退出时崩溃

时间:2011-05-27 13:17:47

标签: iphone ios uiviewcontroller uidocumentinteraction

我的主菜单上有一个常规的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文件。是的,这本身就错了)

1 个答案:

答案 0 :(得分:1)

我想知道问题是否是在视图创建期间执行此操作。因此,当用户关闭文档预览时,它将返回到未完全形成的UIView。那么也许首先构建并加载视图然后从viewDidAppear执行UIDocument?