我正在努力在我的Link Button
中触发html WebView
的事件。我无法找到解决办法。我正在做的是:
public void ViewDidLoad(bool animation)
{
var yourWebView = new UIWebView(new CGRect("YourViewFrame"));
string htmlString = "<html>Hey! try this, I'm sure It will work, Now, <a href='Home.html'>ClickMe</a> Go for it...</html>";
yourWebView.LoadHtmlString(htmlString, null);
}
我尝试过Javascript和webhybrid,但这不足以满足我的要求。我怎样才能让Clicl Me Hit?
答案 0 :(得分:1)
如果您希望从Webview中获取某个事件,那么您必须使用UIWebViewDelegate
来确定已触发的事件。请查看以下代码段。
public void ViewDidLoad(bool animation)
{
var yourWebView = new UIWebView(new CGRect("YourViewFrame"));
yourWebView.Delegate =new YourWebViewDelegate(this);
string htmlString = "<html>Hey! try this, I'm sure It will work, Now, <a href='Home.html'>ClickMe</a> Go for it...</html>";
yourWebView.LoadHtmlString(htmlString, null);
}
创建将处理您的点击操作的委托类。 //魔术
public class YourWebViewDelegate : UIWebViewDelegate
{
UIViewController CurrentInstance;
public YourWebViewDelegate(UIViewController _currentInstance)
{
CurrentInstance = _currentInstance;
}
public override bool ShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
{
if (navigationType == UIWebViewNavigationType.LinkClicked)
{
CurrentInstance.NavigationController.PushViewController(new YourViewControllerToNavigate(), true);
}
return true;
}
}
干杯!!