简体   繁体   中英

How to add button to annotation view in XCode(iOS SDK)

In MKAnnotation there are just title and subtitle, and i don't add anything control to annotation. How to I add a button?

Try using following delegate method of Map View. You can set right call out accessory view as button

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

MKAnnotationView *view = nil; 
//MKPinAnnotationView *view=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"HotSpotsLoc"];

if(annotation !=mapView.userLocation){
    view = (MKAnnotationView *) 
    [mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"]; 
    if(nil == view) { 
        view = [[[MKAnnotationView alloc] 
                 initWithAnnotation:annotation reuseIdentifier:@"identifier"] 
                autorelease];           
    }


    ParkPlaceMark *currPlaceMark = annotation;
    NSLog(@"%i",currPlaceMark.position);

        view.image = [UIImage imageNamed:@"pin.png"];

    UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    view.rightCalloutAccessoryView=btnViewVenue;
    view.enabled = YES;
    view.canShowCallout = YES;
    view.multipleTouchEnabled = NO;
    //view.animatesDrop = YES;

}       
return view;
}

Edit: Disregard this answer. Your complete question was not being shown because of bad markup and I extrapolated (incorrectly) what your question was.


You can drag anything onto the UITableViewCell you want to from the objects palette at right.

If you want to add it as the accessoryView however, do not do that. Add it to the interface file as a separate top level object and drag a connection from the accessoryView outlet of the cell to the view/button you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM