我打电话服务,并返回了一堆的纬度和经度这我然后使用MapKit在地图上放置的。MKAnnotationView RightCallOut按钮崩溃我的应用程序,当我点击它
使用MKAnnotationView我加入一个RightCallOutButton到每个注释。因此我不得不创建一个新的MapDelegate。下面的代码。
如果我点击我创建应用程序崩溃的按钮,我从MonoTouch的话说,选择得到一个错误是accings omething这已是GC'd(垃圾回收)。
所以我的问题是,我应该在哪里设置RightCalloutAccessoryView和我应该在哪里创建按钮,如果不是在下面这段代码?
public class MapDelegage : MKMapViewDelegate {
protected string _annotationIdentifier = "BasicAnnotation";
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) {
MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(this._annotationIdentifier);
if(annotationView == null) {
annotationView = new MKPinAnnotationView(annotation, this._annotationIdentifier);
} else {
annotationView.Annotation = annotation;
}
annotationView.CanShowCallout = true;
(annotationView as MKPinAnnotationView).AnimatesDrop = true;
(annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green;
annotationView.Selected = true;
var button = UIButton.FromType(UIButtonType.DetailDisclosure);
button.TouchUpInside += (sender, e) => {
new UIAlertView("Testing", "Testing Message", null, "Close", null).Show();
} ;
annotationView.RightCalloutAccessoryView = button;
return annotationView;
}
}
所以我会在我的MapDelegate类中创建一个List <>?当我摧毁视图时,不清楚你的意思。我在哪里添加PInAnnotations?我以为GetViewForAnnotation每次只处理一个注释? –
好吧,我想我明白了,而且我明白了。我创建了列表并将annoationView添加到列表中。我是否需要担心我创建的列表或将在某些时候被GC破坏的列表? –
一旦这个领域的父实例没有更多的引用,它将由GC完成,但是由于它可能会变大,所以最好尽快确保'父'被丢弃。如果您隐藏/显示视图(或保留缓存并仅在您收到来自iOS的低内存警告时将其清除),则可能还需要手动清除它。 – poupou