在我Xamarin.iOS项目中,我有我自己的委托类的MKMapViewDelegateXamarin.iOS定制Mapdelegate
的子类,在视图控制器设置我的委托作为的MapView的代表。
public override async void ViewDidLoad()
{
base.ViewDidLoad();
mapView.delegate = new MyMapDelegate(this);
}
现在我在我的委托类中为每个Pin添加一个按钮。该按钮为地图绘制覆盖图。在这里,我必须设置mapview.delegate = null
,否则应用程序崩溃。
但是,如果我设置mapView.delegate = null
该应用程序不使用“DequeueReusableAnnotation”方法,当然应用程序不会再使用DidUpdateUserLocation。
的错误,如果我不mapviews委托设置为null,我得到:
System.InvalidOperationException:事件注册覆盖现有的委托。要么只是使用事件或您自己的委托:testApp.iOS.MyMapDelegate MapKit.MKMapView + _MKMapViewDelegate
所以,我怎样才能设置一个Xamarin代表?
编辑
class MyMapDelegate: MKMapViewDelegate
{
... some vars
public MyMapDelegate(MapController mapController)
{
this.mapController = mapController;
}
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
//everything works fine here for AnnotationView
myBtn += (sender,e) => {
//mapView.Delegate = null;
userLocation = mapView.UserLocation.Coordinate
...
mapView.OverlayRenderer = (mv,ol) => myLine;
mapView.AddOverlay(myWay.polyLine,MKOverlayLevel.AboveRoads)
};
}
我的猜测是有可能出现的错误,因为我打电话从MapView的像OverlayRenderer和用户位置的方法呢?
您可以添加'MyMapDelegate'类的代码?特别是您创建并将注释添加到地图的地方。 – apineda
我编辑了我的问题@apineda – Korken55