Search code examples
iosswiftuibuttoncalloutview

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;

Solution

  • 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