2012-06-07 26 views
5

Aby utworzyć adnotację mapę w serii ujęć projektu iOS, użyłem:Dodaj przycisk Ujawnianie MKPointAnnotation

CLLocationCoordinate2D annotationCoord3; 

     annotationCoord3.latitude = 34.233129; 
     annotationCoord3.longitude = -118.998644; 

     MKPointAnnotation *annotationPoint3 = [[MKPointAnnotation alloc] init]; 
     annotationPoint3.coordinate = annotationCoord3; 
     annotationPoint3.title = @"Another Spot"; 
     annotationPoint3.subtitle = @"More than a Fluke"; 
     [_mapView addAnnotation:annotationPoint3]; 

Działa świetnie, ale chciałbym dodać przycisk ujawnienie więc mogę wcisnąć seque do nowego zobacz kontroler i obraz wyświetlacza. czy to możliwe?

Thx z góry,

--bd--

+0

dodać rzeczy do widoków adnotacji nie do adnotacji;) –

Odpowiedz

9

zadeklarować swoją klasę być MKMapViewDelegate. Następnie dodać

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 


    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"String"]; 
    if(!annotationView) { 
     annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"String"]; 
     annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    } 

    annotationView.enabled = YES; 
    annotationView.canShowCallout = YES; 

    return annotationView; 
} 

następnie dodać:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 
    // Go to edit view 
    ViewController *detailViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
    [self.navigationController pushViewController:detailViewController animated:YES]; 

} 

... ViewController może być cokolwiek określone (używam śruty plików ...)

+0

Działa tylko podczas dodawania '[MapView setDelegate: self];' gdzieś w 'viewDidLoad (); 'lub tak :) – doonot

+0

Tak. Aby użyć metod delegowania mapview, musisz najpierw dopasować mkmapviewdelegate w .h i ustawić viewcontroller jako delegata mapview ... Mam nadzieję, że jestem pomocny –

2

Axel odpowiedź jest poprawna (I tylko przegłosowane): musisz zaimplementować MKMapViewDelegate i przypisać jego instancję do właściwości Delegate MKMapView. Dla osób korzystających MonoTouch, oto port:

class MapDelegate : MKMapViewDelegate 
{ 
    public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) 
    { 
     MKAnnotationView annotationView = mapView.DequeueReusableAnnotation ("String"); 
     if (annotationView == null) { 
      annotationView = new MKAnnotationView(annotation, "String"); 
      annotationView.RightCalloutAccessoryView = new UIButton(UIButtonType.DetailDisclosure); 
     } 
     annotationView.Enabled = true; 
     annotationView.CanShowCallout = true; 
     return annotationView; 
    } 

    public override void CalloutAccessoryControlTapped (MKMapView mapView, MKAnnotationView view, UIControl control) 
    { 
     // Push new controller to root navigation controller. 
    } 
} 
Powiązane problemy