I defined a delegate for a Custom WebView Renderer and assigned it – but the override methods are never called. Below my code. Any idea?
Thanks for any help.
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using System.Diagnostics;
using System;
[assembly: ExportRenderer (typeof (tg.CustomWebView), typeof (tg.iOS.CustomWebViewRenderer))]
namespace tg.iOS
{
public class CustomWebViewRenderer: WebViewRenderer
{
// ok - Get's called !
public CustomWebViewRenderer ()
{
Debug.WriteLine ("CustomWebViewRenderer ()");
this.Delegate = new MyCustomWebViewDelegate();
this.LoadUrl ("http://www.google.ch");
// does not work:
//this.ShouldStartLoad = delegate (UIWebView webViewParam, NSUrlRequest request, UIWebViewNavigationType navigationType) {
// Debug.WriteLine("ShouldStartLoad");
// return false;
//} ;
}
public class MyCustomWebViewDelegate : UIWebViewDelegate
{
// get's never called:
public override bool ShouldStartLoad (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
{
Debug.WriteLine("ShouldStartLoad");
return false;
}
public override void LoadFailed (UIWebView webView, NSError error)
{
Debug.WriteLine("Entered");
}
public override void LoadingFinished (UIWebView webView)
{
Debug.WriteLine("Entered");
}
public override void LoadStarted (UIWebView webView)
{
Debug.WriteLine("Entered");
}
}
}
}