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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:19:53+00:00 2026-05-30T14:19:53+00:00

I want to add a button to the annotation view and assign an action

  • 0

I want to add a button to the annotation view and assign an action to it. I’ve kind of figure it out only my code has a small issue.

// so when I touch the pin , and the annotation view is displayed , I create a button and add it to the view

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
    {

        view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    }
    // when the button is pressed , go to another view 

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
        NSLog(@"calloutAccessoryControlTapped");
        ArticleViewController *det = [[ArticleViewController alloc]init];
        det.leTitle = view.annotation.title;
        det.link = @"http://en.wikipedia.org/wiki/San_Francisco";
        [self.navigationController pushViewController:det animated:YES];

    }

Now , the problem is that the first time I touch the annotation and the button is created ,
the

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

function doesn’t work . Only after I deselect the annotation and touch it again it works properly . Could you help me impove my code ? Thanks.

  • 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-30T14:19:54+00:00Added an answer on May 30, 2026 at 2:19 pm

    Found it !

    I just had to add the button in a function that is called before the one I put it first in .

    - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
    {
        MKPinAnnotationView *pinAnnotation = nil;
        if(annotation != mapViewHandler.userLocation) 
        {
            static NSString *defaultPinID = @"myPin";
            pinAnnotation = (MKPinAnnotationView *)[mapViewHandler dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
            if ( pinAnnotation == nil )
                pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
    
            pinAnnotation.canShowCallout = YES;
    
            //instatiate a detail-disclosure button and set it to appear on right side of annotation
            UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            pinAnnotation.rightCalloutAccessoryView = infoButton;
    
        }
    
        return pinAnnotation;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a button on a view dynamically. Here is the code.
i want to add button to my personal app. like google maps has at
I want to add an annotation to a MapView with disclosure button on it
I want to add button which will toggle between normal and satellite view in
I want to add a button on the home screen and want to code
In my view I want an add button on top right corner, when we
I'm making my own minor mode for emacs. Now I want to add button
I want to add a button to JTabbedPane's title bar (similar to the 'open
I want to add Excel button below the html table, that gives an Excel
I want to add a button to each row of a column of an

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.