简体   繁体   中英

iOS - Cannot get a DetailDisclosure for a button in the callout

I am using Swift with iOS 9. No matter what button type I select, except ContactAdd, only and info icon is rendered. I am trying to get a DetailDisclosure icon for the right side of the callout in a mapview. Here is the code:

    let rightButton = UIButton(type: UIButtonType.DetailDisclosure);
    rightButton.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
    annotationView.rightCalloutAccessoryView = rightButton;

Have you created a pin yet? Try adding the button .DetailDisclosure to the pinView

var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? 
pinView!.rightCalloutAccessoryView = UIButton.buttonWithType(.DetailDisclosure) as UIButton

Update This worked for me

let identifier = "pin"
var view: MKPinAnnotationView
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) as UIView
@user2893289
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?
 {
    let annotationView = MKPinAnnotationView(annotation: noseyesAnnotation, reuseIdentifier: "pin")
    annotationView.pinTintColor = noseyesAnnotation.color
    annotationView.canShowCallout = true
    let rightButton = UIButton(type: UIButtonType.DetailDisclosure);
    annotationView.rightCalloutAccessoryView = rightButton;
    return annotationView
}

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