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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:38:53+00:00 2026-05-26T08:38:53+00:00

I’m working with a MapView and have 30 pin locations placed and everything’s working

  • 0

I’m working with a MapView and have 30 pin locations placed and everything’s working great. I added a button in the callout with a rightCalloutAccessoryView. Here’s the button code:

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.rightCalloutAccessoryView = rightButton;
    [rightButton addTarget:self action:@selector(rightButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    return pinView;
}

This works fine and calls the “rightButtonPressed” method. Here’s the implementation of that method:

-(IBAction) rightButtonPressed:(id)sender
{
    NSLog(@"button clicked");
    MapViewController *thisMap = (MapViewController *)[[UIApplication sharedApplication] delegate];
    DetailViewController *dvc = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
    [thisMap switchViews:self.view toView:dvc.view];
}

So, as you see, any time I touch any button from all 30 pin callouts, it goes to the same view (DetailViewController). I want each button to have it’s own view to switch to (it’s where I’m going to place “Directions To Here” and “Directions From Here” etc. as well as the store address and name).

I realize that I could make 30 views and make 30 different methods that could apply to each pin but I know there has to be a more concise code that deals with arrays.

Possible certain arrays could be called in a UILabel on the DetailViewController so it will just load the appropriate information and also give directions to the appropriate location.

This might be a big question and I’ve looked around for some tutorials but haven’t found anything that answers the question exactly. If anyone could get me started (or even point me in the right direction), I’d be totally grateful.

  • 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-26T08:38:53+00:00Added an answer on May 26, 2026 at 8:38 am

    With annotation view callout accessories, it’s much better to use the map view’s own delegate method calloutAccessoryControlTapped to handle the button press instead of using addTarget and your own custom method.

    In the calloutAccessoryControlTapped delegate method, you can directly access the annotation that was tapped using view.annotation without having to figure out which annotation in an array or whatever data structure was tapped.

    Remove the call to addTarget and replace the rightButtonPressed: method with:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
                calloutAccessoryControlTapped:(UIControl *)control
    {
        //cast the plain view.annotation to your custom class so you can
        //easily access your custom annotation class' properties...
        YourAnnotationClass *annotationTapped = (YourAnnotationClass *)view.annotation;
    
        NSLog(@"button clicked on annotation %@", annotationTapped);
    
        MapViewController *thisMap = (MapViewController *)[[UIApplication sharedApplication] delegate];
        DetailViewController *dvc = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
    
        //annotationTapped can be passed to the DetailViewController
        //or just the properties needed can be passed...
        //Example line below assumes you add a annotation property to DetailViewController.
        dvc.annotation = annotationTapped;
    
        [thisMap switchViews:self.view toView:dvc.view];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.