UIDocumentInteractionController在退出时崩溃

我有一个正常的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文件加载按预期,但是当我点击“完成”button文档closures,我留下来盯着我的空白UIViewController – 可以说是如预期。 但是,如果我点击导航“返回”button,那么应用程序崩溃与我的viewDidLoad方法,其中调用presentPreviewAnimatedfind内存访问错误。

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

(顺便说一句,这个视图控制器创build时没有NIB文件,是的,这本身就是错误的)

我想知道这个问题是否在视图创build过程中是这样做的。 因此,当用户closures文档预览时,它将返回到一个不完整的UIView。 所以也许首先build立并加载视图,然后从viewDidAppear做UIDocument?