Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:42:00+00:00 2026-05-31T17:42:00+00:00

How do I keep data associated with an MKAnnotation object after the user taps

  • 0

How do I keep data associated with an MKAnnotation object after the user taps the pin, sees a callout, and taps the disclosure button which opens a detailed view controller? I want to display all data associated with the pin in the detail view controller.

I have a simple MKAnnotation class that looks like:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface VoiceMemoryAnnotation : NSObject <MKAnnotation> {
    NSString * blobkey;
}
@property (nonatomic, retain) NSString * blobkey;

-(id)initWithBlobkey:(NSString *) key andCoordinate:(CLLocationCoordinate2D) c;
@end

I implemented the call back “viewForAnnotation”

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id     <MKAnnotation>)annotation
{
    MKPinAnnotationView*singleAnnotationView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:nil];


// PM: this pin will have a callout (i.e. dont' forget to override title function! Else exception thrown)
    singleAnnotationView.canShowCallout = YES;

// PM: add disclosure button
    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

// PM: when user taps disclosure button, bring them to another page with details about the selected voice memory
       [rightButton addTarget:self action:@selector(showPinDetails:) forControlEvents:UIControlEventTouchUpInside];
    singleAnnotationView.rightCalloutAccessoryView = rightButton;

    return singleAnnotationView;
}

If I understand correctly, the above method is called when you add a VoiceMemoryAnnotation to a map object. When this viewForAnnotation is called, I simply allocate a MKPinAnnotationView object and return it. When the user taps this retuned pin, they see the callout. As soon as they click the disclosure button it calls “showPinDetails”:

- (void)showPinDetails:(id)sender
{


    detailViewController = [[MemoryDetailViewController alloc]initWithNibName:@"MemoryDetailViewController" bundle:nil];
    [self presentModalViewController:detailViewController animated:YES];

}

The problem is the “sender” object does not contain any information about which pin was selected. Is there some way I can pass in the selected annotation to the showPinDetails method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:42:02+00:00Added an answer on May 31, 2026 at 5:42 pm

    In the showPinDetails: method, you can get the currently selected annotation from the map view’s selectedAnnotations property.

    That property is an NSArray but since the map view only allows one annotation to be selected at a time, you would just use the object at index 0. For example:

    - (void)showPinDetails:(id)sender
    {
        if (mapView.selectedAnnotations.count == 0)
        {
            //no annotation is currently selected
            return;
        }
    
        id<MKAnnotation> selectedAnn = [mapView.selectedAnnotations objectAtIndex:0];
    
        if ([selectedAnn isKindOfClass[VoiceMemoryAnnotation class]])
        {
            VoiceMemoryAnnotation *vma = (VoiceMemoryAnnotation *)selectedAnn;
            NSLog(@"selected VMA = %@, blobkey=%@", vma, vma.blobkey);
        }
        else
        {
            NSLog(@"selected annotation (not a VMA) = %@", selectedAnn);
        }
    
        detailViewController = [[MemoryDetailViewController alloc]initWithNibName:@"MemoryDetailViewController" bundle:nil];
        [self presentModalViewController:detailViewController animated:YES];
    }
    

    Instead of using a custom button action method, it can be easier to use the map view’s calloutAccessoryControlTapped delegate method which lets you get access to the selected annotation more directly. In viewForAnnotation, remove the addTarget and just implement the delegate method:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
        calloutAccessoryControlTapped:(UIControl *)control
    {
        id<MKAnnotation> selectedAnn = view.annotation;
    
        if ([selectedAnn isKindOfClass[VoiceMemoryAnnotation class]])
        {
            VoiceMemoryAnnotation *vma = (VoiceMemoryAnnotation *)selectedAnn;
            NSLog(@"selected VMA = %@, blobkey=%@", vma, vma.blobkey);
        }
        else
        {
            NSLog(@"selected annotation (not a VMA) = %@", selectedAnn);
        }
    
        //do something with the selected annotation... 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If your data change after the application is deployed, how do you keep the
What is recommended way to keep a user configuration data in Unix/Linux? My programming
What are the best ways to keep data synchronized between in memory cache and
Short version: assuming I don't want to keep the data for long, how do
I have a great deal of data to keep synchronized over 4 or 5
I need to keep a field in a data-base and update it with a
I keep on getting this error error: expected specifier-qualifier-list for core data code im
I'm looking for a data structure (or structures) that would allow me keep me
For our application, we keep large amounts of data indexed by three integer columns
What chances do I have to instantiate, keep and serialize/deserialize to/from binary data Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.