gpt4 book ai didi

Xamarin iOS WKWebView DidFinishNavigation 和 DidStartProvisionalNavigation 没有被调用

转载 作者:行者123 更新时间:2023-12-04 21:56:15 24 4
gpt4 key购买 nike

我正在 iOS Xamarin 中实现 WKWebView,我想在加载开始和加载完成时做一些事情。我已经实现了 IWKNavigationDelegate 并添加了以下函数,但没有一个被调用。我错过了什么吗

类定义

 public partial class MasterViewController : UIViewController,IScanSuccessCallback, IWKScriptMessageHandler, IWKNavigationDelegate
{ }

导航委托(delegate)功能
    public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
{
Console.WriteLine ("DidFinishNavigation");
}

public void DidFailNavigation( WKWebView webView, WKNavigation navigation, NSError error )
{
// If navigation fails, this gets called
Console.WriteLine("DidFailNavigation");
}
public void DidFailProvisionalNavigation( WKWebView webView, WKNavigation navigation, NSError error )
{
// If navigation fails, this gets called
Console.WriteLine("DidFailProvisionalNavigation");
}
public void DidStartProvisionalNavigation( WKWebView webView, WKNavigation navigation )
{
// When navigation starts, this gets called
Console.WriteLine("DidStartProvisionalNavigation");
}

最佳答案

补充杰森的回答。

您缺少所需的 ExportAttribute对于可选的委托(delegate)方法,Xamarin Studio 自动完成引擎应该在您每次实现任何 IFooInterface 时为您生成当Foo是一个 ObjC 委托(delegate),您键入 override (它应该列出可选的而不是可选的成员)。 ExportAttribute只有可选成员(c# 接口(interface)中的非抽象成员)才需要。

enter image description here

在这种特殊情况下,WKNavigationDelegate 的所有成员ObjC 协议(protocol)是可选的,因此您需要 Export属性和 ObjC 选择器作为其参数。

您需要添加using Foundation到您的使用语句,ExportAttribute在里面。

[Export ("webView:didFinishNavigation:")]
public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
{
Console.WriteLine ("DidFinishNavigation");
}

[Export ("webView:didFailNavigation:withError:")
public void DidFailNavigation( WKWebView webView, WKNavigation navigation, NSError error )
{
// If navigation fails, this gets called
Console.WriteLine("DidFailNavigation");
}

[Export ("webView:didFailProvisionalNavigation:withError:")]
public void DidFailProvisionalNavigation( WKWebView webView, WKNavigation navigation, NSError error )
{
// If navigation fails, this gets called
Console.WriteLine("DidFailProvisionalNavigation");
}

[Export ("webView:didStartProvisionalNavigation:")]
public void DidStartProvisionalNavigation( WKWebView webView, WKNavigation navigation )
{
// When navigation starts, this gets called
Console.WriteLine("DidStartProvisionalNavigation");
}

希望这可以帮助。

关于Xamarin iOS WKWebView DidFinishNavigation 和 DidStartProvisionalNavigation 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36754354/

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