Just like when removing the annotation, you can use the map view's selectedAnnotations
property to get access to the selected annotation to update its subtitle
.
The following example assumes you're using the annotation class MKPointAnnotation
(which has a settable subtitle
property) for your annotations but you can replace it with your class as needed:
NSLog(@"Update button clicked");
//e.g. subtitle.text = [[alertView textFieldAtIndex:0] text];
//Make sure there is a selected annotation...
if (self.map.selectedAnnotations.count > 0)
{
//Since only one annotation can be selected at a time,
//the selected annotation is the one at index 0...
id<MKAnnotation> ann = [self.map.selectedAnnotations objectAtIndex:0];
//Make sure the selected annotation is one of our types...
if ([ann isKindOfClass:[MKPointAnnotation class]])
{
MKPointAnnotation *pa = (MKPointAnnotation *)ann;
pa.subtitle = [[alertView textFieldAtIndex:0] text];
}
}