IOS引脚注释最初显示,然后使用自定义图像

我有一个IOS应用程序,显示地图,并让用户从列表中select一个路线。 select后,应用程序在地图上绘制这条路线。 我正在使用自定义图像作为我的路线点。 我第一次运行我的应用程序,并select一个路线,默认的图钉加载在地图上。 如果我刷新我的地图或select另一条路线,我的自定义图像显示完美。 这只是第一次,这是发生。 我正在使用MKAnnotation,而不是MKPinAnnotationView,我确定没有指定PinView的代码。 任何帮助指出我在正确的方向来弄清楚这里发生了什么,将不胜感激。 谢谢!

这些是我的自定义注释类

公共类RouteAnnotation:MKOverlay

{ private CLLocationCoordinate2D _coordinate; private string _title; public override CLLocationCoordinate2D Coordinate { get { return _coordinate; } set { _coordinate = value; } } public override string Title { get { return _title; } } public RouteAnnotation (CLLocationCoordinate2D coord, string t) : base() { _coordinate=coord; _title=t; } } 

公共类ClosestStopAnnotation:MKOverlay

{

  private CLLocationCoordinate2D _coordinate; private string _title; public override CLLocationCoordinate2D Coordinate { get { return _coordinate; } set { _coordinate = value; } } public override string Title { get { return _title; } } public ClosestStopAnnotation (CLLocationCoordinate2D coord, string t) : base() { _coordinate=coord; _title=t; } } 

这是在我的mapview委托类

public override MKAnnotationView GetViewForAnnotation(MKMapView mapView,NSObject annotation){

  MKAnnotationView anView; if (annotation is MKUserLocation) { return null; } if (annotation is RouteAnnotation) { anView = (MKAnnotationView)mapView.DequeueReusableAnnotation (ranv); if (anView == null) anView = new MKAnnotationView (annotation, ranv); anView.Image = UIImage.FromFile ("stop20.png"); anView.CanShowCallout = true; return anView; } if (annotation is ClosestStopAnnotation) { anView = (MKAnnotationView)mapView.DequeueReusableAnnotation (canv); if (anView == null) anView = new MKAnnotationView (annotation, canv); anView.Image = UIImage.FromFile ("closeststop40.png"); anView.CanShowCallout = true; anView.Selected = true; return anView; } 

在我的视图控制器中,在一个名为GetClosestStop的方法中,我循环点并放置注释(点是一个RoutePoint对象的列表)

  foreach (RoutePoint p in points) { if (p.Latitude != response.Latitude && p.Longitude != response.Longitude) { String pName = p.Name; var stopCoord = new CLLocationCoordinate2D (p.Latitude, p.Longitude); RouteAnnotation stop = new RouteAnnotation (stopCoord, pName); stops [i] = stopCoord; mapView1.AddAnnotation (stop); anns [i] = stop; i++; } else { coord = new CLLocationCoordinate2D (response.Latitude, response.Longitude); close = new ClosestStopAnnotation (coord, title); mapView1.AddAnnotation (close); mapView1.SelectAnnotation(close, false); stops [i] = coord; i++; } } 

无论何时刷新button被点击,或者select了其他路线,地图都会被清除,GetClosestStop被再次调用。

经过很多debugging和尝试不同的方法,我意识到我的mapView委托没有被分配,直到注释被循环和添加后。 这就是为什么默认的图钉只在第一次运行时才使用。 谢谢您的帮助!