2010-12-22 48 views
2

其實我正在開發一些應用程序,它在我的MKMapView中顯示註釋,這些註釋應該是可點擊的,並將一個參數傳遞給方法。
現在的問題是如何在點擊披露按鈕時將參數傳遞給下一個功能。
對於註釋的格式,我使用- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation方法來顯示披露按鈕。但問題是,如何從當前顯示的Annotation對象中獲取值?MKAnnotationView並將數據傳遞給另一個功能

我對Annotation(只有相關部分)代碼:

@synthesize coordinate, id, title, subtitle; 

+ (id)annotationWithCoordinate:(CLLocationCoordinate2D)coordinate { 
    return [[[[self class] alloc] initWithCoordinate:coordinate] autorelease]; 
} 

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate { 
    self = [super init]; 

    if(nil != self) { 
     self.coordinate = coordinate; 
    } 

    return self; 
} 

並且觸摸披露按鈕時,該方法- (void)displayInfo:(NSNumber *) anId;應移交Annotation.idanId PARAM被調用。

披露按鈕與代碼生成:

UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

    dropPin.rightCalloutAccessoryView = disclosureButton; 
    dropPin.animatesDrop = YES; 
    dropPin.canShowCallout = YES; 

所以 - 問題:
我如何可以傳遞參數去功能或閱讀點擊Annotationid

我以爲我可以做一個處理的揭示按鈕與UIButton的選擇器(但 - 如何通過身份證?)或與- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control(再次 - 如何通過ID?)。

我希望你知道我的意思,非常感謝你的答案! :)

+0

此外,在您的註解類,看起來你已經聲明瞭一個名爲「ID」屬性?強烈建議你把它命名爲別的東西,正如ennuikiller回答的那樣,你甚至可能不需要它。 – Anna 2010-12-22 13:45:23

+0

這是個好主意;-),你是對的。感謝您的幫助輸入:)。 – thedom 2010-12-22 13:52:52

回答

4

在calloutAccessoryControlTapped註釋通過視圖可用:

MKAnnotation *annotation = view.annotation; 
相關問題