QuickLook ShouldOpenUrl委托方法未触发

时间:2018-11-06 12:42:08

标签: ios swift xamarin.ios quicklook

我正在使用QuickLook来预览图像,PDF和Microsoft Office文档。预览文档可以很好地工作,但是每当我尝试打开文档的链接时,其ShouldOpenUrl委托方法都不会触发。以下是我尝试过的代码。

我在具有iOS v11的iPhone和iPad上测试了我的应用程序。

// Open documents using title and file url
public void OpenDocument(string title, string url)
{
    var rootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
    var previewViewController = new QLPreviewController();
    previewViewController.DataSource = new DocumentPreviewDataSource(title, url);

    previewViewController.Delegate = new PreviewControllerDelegate();

    rootViewController.PresentViewController(previewViewController, true, null);
}

// QLPreviewControllerDelegate Implementation
public class PreviewControllerDelegate : QLPreviewControllerDelegate
{
    public override bool ShouldOpenUrl(QLPreviewController controller, NSUrl url, IQLPreviewItem item)
    {
        Console.WriteLine("PreviewControllerDelegate::ShouldOpenUrl: {0}", url.AbsoluteString);
        return true;
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用swapcase

s='ABCD'
print(s.swapcase())
  

在OpenDocument方法中

abcd
  

并覆盖weakdelegatepublic partial class xxxViewController : UIViewController,IQLPreviewControllerDelegate,IQLPreviewControllerDataSource //. . . 中的方法

public void OpenDocument()
{
  var previewViewController = new QLPreviewController();

  previewViewController.View.Frame = View.Bounds;

  previewViewController.WeakDelegate = this;

  previewViewController.WeakDataSource = this;

  this.PresentViewController(previewViewController, true,null);

}

我使用上面的代码,它工作正常。