2012-12-03 15 views
5

टैप किया गया है मेरे मानचित्र एनोटेशन में, मेरे पास कॉलआउट में प्रत्येक एक्सेसरी व्यू के रूप में UIButton है। - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control विधि में, मैं कैसे पता लगा सकता हूं कि प्रत्येक ईवेंट को संभालने के लिए कौन सा सहायक दृश्य स्पर्श किया गया था?आईओएस अंतर करता है कि किस कॉलआउट एक्सेसरी को

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

if ([annotation isKindOfClass:[MKUserLocation class]]) 
    return nil; 

MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"]; 

UIButton *calloutButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
UIButton *directionsButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
directionsButton.frame = CGRectMake(0, 0, 23, 23); 
[directionsButton setBackgroundImage:[UIImage imageNamed:@"directions.png"] forState:UIControlStateNormal]; 

MyPin.leftCalloutAccessoryView = directionsButton; 
MyPin.rightCalloutAccessoryView = calloutButton; 
MyPin.draggable = NO; 
MyPin.highlighted = NO; 
MyPin.animatesDrop= YES; 
MyPin.canShowCallout = YES; 
MyPin.pinColor = MKPinAnnotationColorRed; 

return MyPin; 
} 

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 

Annotation *ann = view.annotation; 

if ([control tag] == 1) { 

    CLLocationCoordinate2D currentCoords = {ann.coordinate.latitude, ann.coordinate.longitude}; 

    MKPlacemark *place = [[MKPlacemark alloc] initWithCoordinate: currentCoords addressDictionary:nil]; 
    MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark: place]; 
    destination.name = ann.title; 
    destination.url = [NSURL URLWithString:@"http://www.wccca.com/PITS"]; 
    NSArray *items = [[NSArray alloc] initWithObjects: destination, nil]; 
    NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys: 
          MKLaunchOptionsDirectionsModeDriving, 
          MKLaunchOptionsDirectionsModeKey, nil]; 
    [MKMapItem openMapsWithItems: items launchOptions: options]; 

} 

if ([control tag] == 2) { 

    MKCoordinateRegion region; 
    region.center.latitude = ann.coordinate.latitude; 
    region.center.longitude = ann.coordinate.longitude; 
    region.span.latitudeDelta = 0.02; 
    region.span.longitudeDelta = 0.02; 

    [self.mapView setRegion:region animated:YES]; 
} 

} 
+0

आप पहले से ही टैग का उपयोग कर रहे .. नहीं है यह जानने के लिए पर्याप्त है कि कौन सा यूबूटन टैप किया गया था? – poncha

+0

यह किसी कारण से काम नहीं कर रहा है। मुझे नहीं पता क्यों! –

उत्तर

18

बल्कि स्थापित करने और टैग का उपयोग करने से, आप बस अगर control बाईं या दाईं गौण दृश्य है जांच कर सकता है: यहाँ मेरी कोड है

if (control == view.leftCalloutAccessoryView) { 
    //handle left control tap...   
} 
else 
if (control == view.rightCalloutAccessoryView) { 
    //handle right control tap...  
} 
अपने कोड में
+0

बिल्कुल सही। धन्यवाद –