3

我在支持 iPhone 和 iPad 的通用应用程序中工作。我目前使用 UIDocumentInteractionController 来呈现 PDF 并在该 PDF 上提供一些选项(最重要的是打印功能)。随着概述的出现和预览中的 RightBarButtonItem 正确允许我打印,一切似乎都可以在 iPad 上完美运行。但是,使用 iPhone 时,当我单击 RightBarButtonItem 时收到错误消息:

Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].

使用典型的操作表解决此问题相对简单:

ActionSheet.ShowFromTabBar(this.TabBarController.TabBar);
ActionSheet.ShowFromToolbar(this.NavigationController.ToolBar);

然而,随着文档控制器的成熟,我发现很难掌握如何去做。与我在这里找到的其他实现相比,交互控制器的代码非常标准,所以我确信我缺少一些小东西。这是实现:

invoiceInteractionController = UIDocumentInteractionController.FromUrl(url);
invoiceInteractionController.Delegate = new UIDocumentInteractionControllerDelegateClass(this);

InvokeOnMainThread(delegate{
    if (!DeviceHelper.IsIPhone())
        invoiceInteractionController.PresentOptionsMenu(NavigationItem.RightBarButtonItem, true);
    else {
        invoiceInteractionController.PresentPreview(true);
}
});

现在,如果设备是 iPhone,我只是直接跳到预览,如您在此代码中所见。当按下右上角的条形按钮项时,问题出在预览控制器内,这会引发上述问题。但是,顺便说一句,将 PresentPreview() 替换为:

invoiceInteractionController.PresentOptionsMenu(new RectangleF(320,320,0,500), this.NavigationController.Toolbar, true);

这也会引起同样的错误。

我几乎想知道它是否与我的委托类有关,如下所示:

public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate
{
    UIViewController viewC;

    public UIDocumentInteractionControllerDelegateClass (UIViewController controller)
    {
        viewC = controller;
    }

    public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
    {
        return viewC;
    }

    public override UIView ViewForPreview (UIDocumentInteractionController controller)
    {
        return viewC.View;
    }

    public override RectangleF RectangleForPreview (UIDocumentInteractionController controller)
    {
        return viewC.View.Frame;
    }
}

与往常一样,非常感谢任何帮助。

4

1 回答 1

0

我将基本上将此标记为已解决,因为它不会导致应用程序或控制器无法工作。最终我相信我将不得不用我自己的控制器卷来替换整个东西,因为它对品牌/皮肤并不友好。如果它能够提供从标签栏呈现的能力,那就太好了。

我确实注意到的一件事是,当在 Interface Builder 中定义的选项卡栏中的导航控制器中显示它时,文档控制器将抛出相同的警告,但永远不会出现。以编程方式创建标签栏并明确定义 RectangleF 将允许控制器显示,但仍会引发警告。

我最好的猜测是 PresentPreview(true) 假设它应该从调用事件的控件中呈现,不幸的是,它是从右栏按钮呈现的操作表中的一个按钮。我愿意接受更多建议以使警告消失。

于 2012-09-21T13:29:37.597 回答