Reputation: 271
I have a custom MKPinAnnotationView created as so:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = false
pinView!.animatesDrop = true
pinView!.pinColor = .Red
pinView!.draggable = true;
} else {
pinView!.annotation = annotation
}
return pinView
}
Then I add a subview to it later with a button like this:
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
view.addSubview(confirm)
}
The problem is that the button inside the subview is not responsive at all. What could be causing that? I already tried playing around with userInteraction enabled. Thanks
Upvotes: 2
Views: 3723
Reputation: 975
Not sure if this fits or helps but in my case I where I have similar code I set
pinView!.canShowCallout = true
and then if you want a simple way to catch the button clicks I put a func inside of my ViewContriller:
func buttonClicked (sender : UIButton!) {
println("Button Clicked")
}
It sounds like you want to do something a bit different though.
Opps.. in previous answer I forgot that I added the button just above the
return pinView
....
let button : UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as UIButton
button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
pinView!.rightCalloutAccessoryView = button
return pinView
Now the buttonClicked func can catch the callout.
Upvotes: 3