1

I dont want pin to be call directly on map, I want this on button action to call pin annotation.

When I call this method on button click event my app was crash. I want to call annotation on button click. Can I call this all method on button?

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.map dequeueReusableAnnotationViewWithIdentifier: @"restMap"];
    if (pin == nil) {
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"restMap"] autorelease];
    } else {
        pin.annotation = annotation;
    }
    pin.pinColor = MKPinAnnotationColorRed
    pin.canShowCallout = YES;
    pin.animatesDrop = NO;
    UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    NSInteger annotationValue = [self.annotations indexOfObject:annotation];
    detailButton.tag = annotationValue;
    [detailButton addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside];
    pin.rightCalloutAccessoryView = detailButton;
    return pin;
}  
halfer
  • 19,824
  • 17
  • 99
  • 186
Rani
  • 3,333
  • 13
  • 48
  • 89
  • Check this out, might help you. [Building Custom Map Annotation Callouts](http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/) – Jason May 19 '11 at 13:32
  • Go for the [Apple's MapCallout Sample Code](http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html) They Have done excatly what you want. – Shrey May 19 '11 at 15:21

1 Answers1

0

The method that you are trying to call is a mapView delegate method and should only be called by your MapView. This method is only for providing the annotation's view "on demand" when the mapView needs it. I.e. When the annotation is in or about to move into the mapView's visible region.

You need to add an annotation object to your mapView. This object must conform to the MKAnnotation Protocol. http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKAnnotation_Protocol/

You will add the object to the mapView by calling [yourMapView addAnnotation: yourAnnotationObject] in the IBAction method that is called when your button is pushed.

timthetoolman
  • 4,613
  • 1
  • 22
  • 22