在我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