【问题标题】:Presenting view controllers on detached view controllers is discouraged in iOS 8在 iOS 8 中不鼓励在分离的视图控制器上显示视图控制器
【发布时间】:2015-09-09 11:38:17
【问题描述】:

我想将 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];

不显示窗口。

【问题讨论】:

    标签: ios ipad uiactivityviewcontroller


    【解决方案1】:

    发生这种情况是因为您的 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

    【讨论】:

    • 我试过了,但我收到错误,因为“由于未捕获的异常 'NSGenericException' 而终止应用程序,原因:'UIPopoverPresentationController (<_uialertcontrolleractionsheetregularpresentationcontroller:>) 之前应该有一个非零的 sourceView 或 barButtonItem演示发生了。'"
    • 我需要为 iPad 使用 popovercontroller。请查看stackoverflow.com/questions/25644054/…
    • 什么是 myButton 我没有得到
    • 我在附件之前关闭视图([self dismissPopupViewControllerWithanimation:nil];)这就是为什么我得到“警告:尝试在 上呈现 其视图不在窗口层次结构中!”现在我在发送电子邮件后解雇。现在它工作正常。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2013-11-22
    • 2018-02-21
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多