UIDocumentInteractionController 退出时崩溃

发布于 2024-11-10 06:07:59 字数 1467 浏览 0 评论 0原文

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

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];
}

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑕疵 2024-11-17 06:07:59

我想知道问题是否在于您在视图创建期间执行此操作。这样,当用户关闭文档预览时,它会返回到未完全形成的 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 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文