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

落爺英雄遲暮 提交于 2019-12-04 02:35:27

问题


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


回答1:


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;
}



回答2:


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.



来源:https://stackoverflow.com/questions/6550201/how-to-add-button-to-annotation-view-in-xcodeios-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!