Pregunta

I've got a situation where I have some custom annotations on mapview. When these annotations are selected I change the image to a selected state via the

didSelectAnnotationView 

method with a call to [view setImage] and I also show a callout bubble. The callout has an accessory view that adds a new subview with more information in it when tapped. All this works fine, except that when I tap the callout accessory view I want the callout to disappear, but the selected image state to remain. Currently the only way I know how to dismiss the callout is via

 didDeselectAnnotationView

however this is also where I would set the image state to be the default unselected image.

Does anyone know if it is possible to dismiss the callout only but retain the selected state on my annotation?

I've sort of got this working by setting a boolean when the detailView has been added to decide whether or not to remove the "active" image. However it becomes tricky when I select a new annotation as I end up with multiple annotations showing the selected state image. I've tried looping through all annotations and setting their image to the "off" state but this doesn't seem to work and I've tried setting a reference to the currently selected annotation and changing the image on that, but again it hasn't worked.

Example flow:

  • User selects a pin
  • didSelectAnnotationView is called
  • Pin image changes to "active" and callout is shown
  • User taps accessory view in callout.
  • BOOLEAN popOverShowing is set to YES
  • didDeselectAnnotationView is called. As popOverShowing is YES the image is not changed to off state but callout disappears
  • User taps New annotation
  • Popover disappears and popOverShowing set to NO
  • New annotation is set to "active" image
  • all other annotations should get reset to off image (this is what doesn't seem to happen)
¿Fue útil?

Solución

Keep the reference of previousPin set it off in didSelectAnnotationView unless is nil. Then set the new selected pin as previousPin. Hope it helps.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top