2009-12-06 36 views
5

我想添加一個註解到一個MapView上,並且透露按鈕,我無法弄清楚它。添加一個可點擊的註釋到UIMapView

我創建了符合MKAnnotation協議,然後創建的MapView並添加標地標類:

// Add annotation information 
PlaceMark *venuePlacemark = [[PlaceMark alloc] initWithCoordinate:location]; 
venuePlacemark.locationTitle = [locationDictionary valueForKey:VENUE_NAME_KEY]; 
venuePlacemark.locationSubtitle = @"Touch to show in Google Maps"; 

// Create the accessory button on the placemark 
[venueMap addAnnotation:venuePlacemark]; 
[venueMap setRegion:region animated:TRUE]; 
[venueMap regionThatFits:region]; 

這一切工作和引腳顯示,當碰到顯示正確叫出文字。我無法弄清楚如何在呼叫中添加一個披露按鈕。對不起,如果這是小學和任何幫助,將不勝感激。

戴夫

+0

這是一個很好的問題。關於這方面的文檔有點可怕。當他們編寫這些文檔時,蘋果真的假設他們有很多關於SDK的經驗。 –

回答

9

想我已經想通了...實施了以下的委託方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    MKPinAnnotationView *dropPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"venues"]; 

    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [disclosureButton addTarget:self action:@selector(mapCallOutPressed:) forControlEvents:UIControlEventTouchUpInside]; 

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

    return dropPin; 
} 
+2

This works but but [disclosureButotn addTarget] you should be using the predefined delegate method - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped :(UIControl *)control –

+0

Thanks Jasconius ...會給它一個旋風...... –