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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:30:35+00:00 2026-05-17T21:30:35+00:00

I don’t think I am understanding this correctly, I added the annotation to the

  • 0

I don’t think I am understanding this correctly, I added the annotation to the map. I can see it, the color is red. However, I want to change it to purple and I want it as a button. So I put it as follows:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    //[self generateAnnotation];
    CLLocationCoordinate2D aCoordinate;
    aCoordinate.latitude = 32.224023;
    aCoordinate.longitude = -110.965159;
    MapAnnotation * an1 = [[[MapAnnotation alloc] initWithCoordinate: aCoordinate] autorelease];
    an1.title = @"Party at Malloneys";
    an1.subtitle = @"213 N. 4th Ave";
    //[annotationArray addObject:an1];
    [mapView addAnnotation:an1];

    self.locationManager = [[[CLLocationManager alloc] init] autorelease];

    self.locationManager.delegate=self;
        self.locationManager.distanceFilter = kCLLocationAccuracyBest;
        [self.locationManager startUpdatingLocation];

}



- (void) mapView:(MKMapView *) mapView
    didAddAnnotationViews:(NSArray *) views
{
    for (MKPinAnnotationView * mkaview in views)
    {

        mkaview.pinColor = MKPinAnnotationColorPurple;
        UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        mkaview.rightCalloutAccessoryView = button;
    }

}




- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView * annView = (MKPinAnnotationView*) [mapView dequeueReusableAnnotationViewWithIdentifier:@"an1"];
    if (!annView)
    {
        annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"an1"] autorelease];
    annView.pinColor = MKPinAnnotationColorGreen;
    annView.animatesDrop = YES;
    annView.canShowCallout = YES;
    }
     else {
         annView.annotation = annotation;
     }

    return annView;
}   

I don’t understand the two delegates above, viewForAnnotation is supposed for setting the view for the annotation right? and the didAddAnnotationViews delegate method is executed after the view is loaded?? Please correct my understanding if this is wrong. And how can I fix this so that I can change color and add a button.

  • 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-17T21:30:35+00:00Added an answer on May 17, 2026 at 9:30 pm

    The didAddAnnotationViews method fires when one or more annotations are added to a map. You can update other parts of your UI or do other logic knowing that the annotations are “ready”. It’s not necessarily a place to update the appearance of an annotation.

    The viewForAnnotation method is where you tell how an annotation looks. It’s like the cellForRowAtIndexPath method in the table view.

    What happens when you run the code in your question? Why don’t you just set the purple pinColor and accessory in the viewForAnnotation method and forget about the didAddAnnotationViews method?

    Also note that in didAddAnnotationViews, the views array contains MKAnnotationView objects and not just MKPinAnnotationView objects. So if one of the annotation views is not a MKPinAnnotationView, the line setting the pinColor will crash.

    Edit:
    Your pins are coming up red even with these methods implemented that set the pin color to something else. Most likely cause is that the mapView’s delegate is not set. In viewDidLoad, before you call addAnnotation say:

    mapView.delegate = self;
    

    You should then remove the didAddAnnotationViews method and set the pinColor to purple and add the accessory button in viewForAnnotation.

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

Sidebar

Related Questions

Don't think my virtualhost is working correctly. This is what I have inside of
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if anyone can help me with this or if it's even possible.
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't ask me why but i can't use this method because I need to
Don't know why but I can't find a solution to this. I have 3
Don't want to sort the entries. using this does not preserve the order as
Don't think this is a repost, difficult to search for the word between because
don't know what happened in my jcrop selection. I think I pressed some keys

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.