gpt4 book ai didi

iphone - UIDocumentInteractionController 的奇怪问题

转载 作者:行者123 更新时间:2023-12-03 18:23:08 25 4
gpt4 key购买 nike

我不知道这段代码有什么问题,但每次运行应用程序时,显示菜单后,应用程序都会崩溃。

NSString * path = [[NSBundle mainBundle] pathForResource:@"tung" ofType:@"doc"];

UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];

docController.delegate = self;

//[docController presentPreviewAnimated:YES];

CGRect rect = CGRectMake(0, 0, 300, 300);
[docController presentOptionsMenuFromRect:rect inView:self.view animated:YES];

我得到的错误:

*** Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.'

我现在应该做什么?

最佳答案

要通过“一次性”UIDocumentInteractionController 预览文档,您应该在 interactionControllerWithURL 之后保留它,并在 UIDocumentInteractionControllerDelegate 方法 documentInteractionControllerDidDismissOptionsMenu 中自动释放它。正如 David Liu 所说,释放它会崩溃。但自动释放有效。我已经检查过确实调用了 dealloc。

下面的代码应该可以工作:


- (void)previewDocumentWithURL:(NSURL*)url
{
UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
preview.delegate = self;
[preview presentPreviewAnimated:YES];
[preview retain];
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[controller autorelease];
}

关于iphone - UIDocumentInteractionController 的奇怪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2910787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com