开发者

How to call pin annotation on button click in iPhone

开发者 https://www.devze.com 2023-03-06 20:25 出处:网络
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 cl

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 = [[开发者_JS百科[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;
}  


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消