我打電話服務,並返回了一堆的緯度和經度這我然後使用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