gpt4 book ai didi

ios - QuickLook ShouldOpenUrl 委托(delegate)方法未触发

转载 作者:行者123 更新时间:2023-11-30 11:02:26 32 4
gpt4 key购买 nike

我正在使用QuickLook预览图像、Pdf 和 Microsoft Office 文档。预览文档工作正常,但每当我尝试打开文档中的链接时,其 ShouldOpenUrl 委托(delegate)方法不会触发。以下是我尝试过的代码。

我使用装有 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;
}
}

最佳答案

您可以使用weakdelegate

public partial class xxxViewController : UIViewController,IQLPreviewControllerDelegate,IQLPreviewControllerDataSource
//. . .

in method OpenDocument

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

previewViewController.View.Frame = View.Bounds;

previewViewController.WeakDelegate = this;

previewViewController.WeakDataSource = this;

this.PresentViewController(previewViewController, true,null);

}

And override the method in QLPreviewControllerDelegate and QLPreviewControllerDataSource

public nint PreviewItemCount(QLPreviewController controller)
{
return 1;
}

public IQLPreviewItem GetPreviewItem(QLPreviewController controller, nint index)
{
return new NSUrl("your url");
}

[Export("previewController:shouldOpenURL:forPreviewItem:")]
public bool ShouldOpenUrl(QLPreviewController controller, NSUrl url, IQLPreviewItem item)
{
Console.WriteLine("PreviewControllerDelegate::ShouldOpenUrl: {0}", url.AbsoluteString);
return true;
}

[Export("previewControllerWillDismiss:")]
public void WillDismiss(QLPreviewController controller)
{
// do some thing
}

我使用上面的代码,效果很好。

关于ios - QuickLook ShouldOpenUrl 委托(delegate)方法未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53172154/

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