0

I have a simple maps app with multiple pins on a map view. My intention is to tap a pin, show a callout with an accessory view, push to a Detail View Controller where you can edit that pin/locations details. This all works fine, but once i pop the Detail View Controller the callout on the map view is still there, which i want, but it still has the old uneditied values. How can i refresh/update the callout view once the Detail View Controller is popped?

I am using Core Data with a simple database. I have tried using controllerdidchangecontent, Map View Controller Will Display methods etc but my main problem is identifying which object has been added/updated/deleted and which is the corresponding callout/selected pin.

Any help appreciated...

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

The only way I could find to update the callout info was to mess directly with the subviews of the callout.

The callout view is the first subview of the annotation view.

In the following example, I update the subtitle.The title label is the 6th and the subtitle is the 7th subview of the callout:

if (myAnnotationView.subviews.count > 0)
    ((UILabel*)[((UIView*)[myAnnotationView.subviews objectAtIndex:0]).subviews objectAtIndex:7]).text = @"Some example";
Nicu Surdu
  • 8,172
  • 9
  • 68
  • 108
  • Indeed, but changing the content of the subtitle (index 7) does not update the callout (it didn't work for me). Also, changing the title does not resize the callout. – Eduardo Mauro Nov 23 '12 at 19:17
  • @EduardoMauro Can you please tell me on what iOS have you tried this ? Maybe they've changed the layout in newer than iOS 5.1.1, in which case I have a problem as well :). Regarding the resizing, yes, most probably you'll have to do that manually as well :( ... – Nicu Surdu Nov 23 '12 at 23:08
  • Unfortunately, I don't have any device running that particular version. The way I detected which is the view that contains the subtitle, is I iterated over all the subview, NSLog-ed [mySubview class] and looked for those who have UILabel as class. But this bring the issue of portability, if you say it's not working on 4.2. If you will go ahead with the test, please leave a comment with your subviews structure, maybe I can make the code adaptable. – Nicu Surdu Nov 26 '12 at 12:17
  • be aware that this (obviously) doesn't not work anymore in iOS7 :( – Nicu Surdu Sep 27 '13 at 08:10
0

Not sure if you had find your answer but the way to do it is to extend MKAnnotation class and creating custom annotation and passing them while creating placemarks. Later you can get them from MKAnnotationView's annotation property.

See a good implementation here

http://www.slideshare.net/360conferences/getting-oriented-with-mapkit-everything-you-need-to-get-started-with-the-new-mapping-framework

Rahul Choudhary
  • 3,789
  • 2
  • 30
  • 30