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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:55:56+00:00 2026-05-26T10:55:56+00:00

I have created a MKAnnotationView and do add a UIButton on it. Now I

  • 0

I have created a MKAnnotationView and do add a UIButton on it. Now I would like that button to remove the pin it is in.

This is how I add the button:

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *pinAnnotation = nil;
    if(annotation != myMapView.userLocation) 
    {
        NSString *defaultPinID = [[NSString alloc] initWithFormat:@"pin%d",pinCount];
        pinAnnotation = (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinAnnotation == nil )
            pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
        pinAnnotation.canShowCallout = YES;

    //// ADDING MY BUTTON
        UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinAnnotation.rightCalloutAccessoryView = deleteButton;
    //// ADDING IT'S ACTION
        [deleteButton addTarget:self action:@selector(deletePin) forControlEvents:UIControlEventTouchUpInside];
    }
    pinCount++;
    return pinAnnotation;
}

As you can see there, I set the action to call this method:

-(void)deletePin
{
    //What to put here...?
}

How can I make that action delete it’s button’s pin?

I figured maybe sending the id thru or something, but am not sure how.

  • 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-26T10:55:57+00:00Added an answer on May 26, 2026 at 10:55 am

    With annotation callout accessory views, do not use your own target/action method.

    Instead, use the map view’s calloutAccessoryControlTapped delegate method which will make this job much easier.

    Remove the addTarget line and your custom method. Then implement the delegate method instead:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
                calloutAccessoryControlTapped:(UIControl *)control
    {
        [mapView removeAnnotation:view.annotation];
    }
    

    Also, unrelated, but the way you are setting the re-use identifier is wrong and defeats re-usability by assigning a different id to every annotation. The following is recommended:

    - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
    {
        MKPinAnnotationView *pinAnnotationView = nil;
        if (annotation != myMapView.userLocation) 
        {
            NSString *reuseId = @"StandardPin";
            pinAnnotationView = (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
            if ( pinAnnotationView == nil )
            {
                pinAnnotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId] autorelease];
                pinAnnotationView.canShowCallout = YES;
    
                UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                pinAnnotationView.rightCalloutAccessoryView = deleteButton;
            }
            else
                //update annotation property if view is being re-used...
                pinAnnotationView.annotation = annotation;
        }
    
        return pinAnnotationView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a volume controller for iTunes but I would like this app
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
I have created a foreign key (in SQL Server) by: alter table company add
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created a SharePoint workflow in visual studio , I have extended this
I have created a style for a listbox item which shows up the button.
Have created a custom navigation menu in wordpress that has some pages and some

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.