2012-06-07 14 views
5

Para crear una anotación de mapa en un proyecto de iOS guión gráfico, he utilizado:botón Agregar Divulgación a 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]; 

Funciona muy bien pero me gustaría añadir un botón de divulgación para que pueda empujar Seque a un nuevo ver el controlador y visualizar la imagen. es posible?

Thx por adelantado,

--bd--

+0

agregar cosas a las vistas de anotación no a las anotaciones;) –

Respuesta

9

declarar su clase para ser un MKMapViewDelegate. A continuación, añadir

- (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; 
} 

Luego agrega:

- (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 puede ser cualquier cosa que haya definido (utilizo para plumilla archivos ...)

+0

sólo funciona cuando se agrega '[MAPview setDelegate: auto];' en algún lugar de 'viewDidLoad (); 'más o menos :) – doonot

+0

Sí. Para utilizar los métodos de delegación de mapview, primero debes ajustar mkmapviewdelegate en .h y configurar viewcontroller como el delegado de mapview ... Espero ser útil –

2

respuesta de Axel es correcto (I just upvoted): debe implementar el MKMapViewDelegate y asignar una instancia del mismo a la propiedad Delegate de MKMapView. Para aquellos que utilizan MonoTouch, aquí está el puerto:

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. 
    } 
} 
Cuestiones relacionadas