Ive got a strange issue here the custom render for iOS is not working, the OnElementChanged is not even being called at all.
I'm using the Xamarin.Forms.Maps plugin and using a custom renderer for iOS and android for some platform specific functionality required, android works fine on the renderer but iOS its not even being call it at all??
Basically looks like this in the iOS project:
[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
namespace SampleApp.iOS.Handlers
{
public class CustomMapRenderer : MapRenderer
{
private UIView _customPinView;
private List<CustomStorePin> _customStorePins;
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
if (Control is MKMapView nativeMap)
{
nativeMap.RemoveAnnotations(nativeMap.Annotations);
nativeMap.GetViewForAnnotation = null;
nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
nativeMap.DidSelectAnnotationView -= OnDidSelectAnnotationView;
nativeMap.DidDeselectAnnotationView -= OnDidDeselectAnnotationView;
}
}
if (e.NewElement != null)
{
CustomMap formsMap = (CustomMap)e.NewElement;
MKMapView nativeMap = Control as MKMapView;
_customStorePins = formsMap.CustomPins.ToList();
formsMap.MapPinSelectedEventHandler += FormsMap_MapPinSelectedEventHandler;
nativeMap.GetViewForAnnotation = GetViewForAnnotation;
nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
nativeMap.DidSelectAnnotationView += OnDidSelectAnnotationView;
nativeMap.DidDeselectAnnotationView += OnDidDeselectAnnotationView;
}
}
}
private void OnTap(UITapGestureRecognizer recognizer)
{
CGPoint cgPoint = recognizer.LocationInView(Control);
CoreLocation.CLLocationCoordinate2D location = ((MKMapView)Control).ConvertPoint(cgPoint, Control);
PerformSelector(new ObjCRuntime.Selector("ShowAnnotation"), null, 0.6f);
}
[Export("ShowAnnotation")]
private void ShowAnnotation()
{
((MKMapView)Control).SelectAnnotation(((MKMapView)Control).Annotations[0], true);
}
}
}
My shared project has CustomMap class:
public class CustomMap : Map
{
}
I've put break points in the CustomMap renderer class in the iOS project and not a single break point gets hit when the map page opens.