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 7932031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:53:32+00:00 2026-06-03T20:53:32+00:00

I have populated a couple of locations on MKMapView using MKPointAnnotation(s). On tapping annotations

  • 0

I have populated a couple of locations on MKMapView using MKPointAnnotation(s). On tapping annotations I am showing some options with UIActionSheet menu. The options have some delete functionality which would delete the selected annotation on map when user taps the delete option on UIActionSheet. The issue is that I am not able to determine which annotation point is clicked, I seem to have no reference to it.

The code that adds annotation point is:

while(looping array of locations)
{
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = {coord of my location}
annotationPoint.title = [anObject objectForKey:@"castTitle"];
annotationPoint.subtitle = [anObject objectForKey:@"storeName"];

[self.mainMapView addAnnotation:annotationPoint];
}

The code to show UIActionSheet on tapping annotation is:

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
    if([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];

    pinView.animatesDrop = YES;
    pinView.canShowCallout = YES;
    pinView.pinColor = [self getAnnotationColor];

    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(showOptions:) forControlEvents:UIControlEventTouchUpInside];
    pinView.rightCalloutAccessoryView = rightButton;

    return pinView;
}

-(IBAction)showOptions:(id)sender
{
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"", @"") delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Delete", @"Delete"),      nil];

        [sheet showInView:[self.view window]];
}
  • 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-06-03T20:53:34+00:00Added an answer on June 3, 2026 at 8:53 pm

    Seems like there are two approaches.

    If only one annotation can be selected at a time, you could access the -selectedAnnotations property of the enclosing MKMapView.

    Another approach is to inspect sender in showOptions:, which is a reference to the UIButton that triggered the action. Find out its enclosing MKAnnotationView, which will give you the associated -annotation. You could then either stash this as an ivar or (my preferred approach) use some runtime magic – in the form of objc_setAssociatedObject(), declared in <objc/runtime.h> – to attach a reference to the annotation to the action sheet, allowing easy retrieval in its delegate callback.

    (You could actually do this back in the button creation phase if you wanted, and attach a reference to the annotation to the UIButton, which can be picked up directly in showOptions: and reattached to the action sheet.

    But [MKMapView selectedAnnotations] I would think is the easier way to go if it suits your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking for a some working code for the last couple of
I have couple of ThreadLocal s populated in my web app. And, while remote
I have a listbox which has a couple of values and is already populated
I have a dropdown menu populated from a table in a MySQL database. It
I have 3 select boxes, all populated with the same data. Using jquery I
I have populated an array with a few html image tags that I have
In a controller, I have populated a map that has a string as key
I have a populated SqlCommand object containing the command text and parameters of various
I'm working with TListView and I have successfully populated each item's caption and first
I have a UITableView populated with a location-based datasource. I'm calling [self updateView]; to

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.