在iOS 8中不鼓励在分离的视图控制器上呈现视图控制器

时间:2015-09-09 11:38:17

标签: ios ipad uiactivityviewcontroller

我想将pdf附加到邮件中,但是当我在iOS 8中运行时,我发现跟随错误

Presenting view controllers on detached view controllers is discouraged.

当我点击邮件时,我正在

Warning: Attempt to present <MFMailComposeViewController:> on <> whose view is not in the window hierarchy!

我使用以下代码来执行此操作,

activityVC = [[UIActivityViewController alloc]initWithActivityItems:PDFDataArray applicationActivities:nil];  
_popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[_popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

不显示窗口。

1 个答案:

答案 0 :(得分:0)

这种情况正在发生,因为您的UIPopoverController尚未显示,仍然不是窗口层次结构的一部分。

预约UIActivityViewController的正确方法如下:

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:PDFDataArray applicationActivities:nil];

if ([activityVC respondsToSelector:@selector(popoverPresentationController)] ) { 
    activityVC.popoverPresentationController.sourceView = myButton;
}    

[self presentViewController:activityVC animated:YES completion:nil];

无需UIPopoverController