Pass id to calloutAccessoryControlTapped

When I click the accessory button, I need to pass itemId, so I can identify the item to go to my detailed view.

Still:

Add annotations:

for (id row in self.detailItem) { Item *i = (Item *) row; CLLocationCoordinate2D destination; destination.latitude = (double) i.latitude; destination.longitude = (double) i.longitude; //i.itemid MapViewAnnotation *destinationAnnotation = [[MapViewAnnotation alloc] initWithTitle: i.name andCoordinate: destination]; [self.mapView addAnnotation: destinationAnnotation]; [destinationAnnotation release]; } 

Add Accessories Button

 - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView *pinAnnotation = nil; if(annotation != mapView.userLocation) { static NSString *defaultPinID = @"myPin"; pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; if ( pinAnnotation == nil ) pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; pinAnnotation.canShowCallout = YES; UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; pinAnnotation.rightCalloutAccessoryView = infoButton; } return pinAnnotation; } 

find the item to go to the detailed view

 -(void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { // get annotation details here. NSLog(@"%@", control); } 
+4
source share
1 answer

Add the itemid property to the itemid class.

When adding annotation, set the property before calling addAnnotation :

 destinationAnnotation.itemid = i.itemid; [self.mapView addAnnotation: ... 

In calloutAccessoryControlTapped , go into the annotation details as follows:

 MapViewAnnotation *annotationTapped = (MapViewAnnotation *)view.annotation; NSLog(@"annotationTapped.itemid = %@", annotationTapped.itemid); 

(If itemid is int , change %@ in NSLog to %d .)

+10
source

All Articles