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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:04:36+00:00 2026-06-16T13:04:36+00:00

Hello and thanks for the help. I am using the following code to set

  • 0

Hello and thanks for the help.

I am using the following code to set the pin colors on my MapView annotations ?

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {




    MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
    if (!pinView) {

        //////////////
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
        pinView.pinColor = MKPinAnnotationColorGreen;
        if([[annotation title] isEqualToString:@"MuRoom"])
        {
            // Do somethingMKAnnotation
            pinView.pinColor = MKPinAnnotationColorRed;

            NSLog( @"data from ann index %@", annTile);
        }
        if([[annotation title] isEqualToString:@"Mike's"])
        {
            // Do somethingMKAnnotation
            pinView.pinColor = MKPinAnnotationColorRed;

            NSLog( @"data from ann index %@", annTile);
        }
        if([[annotation title] isEqualToString:@"Bill's"])
        {
            // Do somethingMKAnnotation
            pinView.pinColor = MKPinAnnotationColorPurple;

            NSLog( @"data from ann index %@", annTile);
        }
        if([[annotation title] isEqualToString:@"Steve's"])
        {
            // Do somethingMKAnnotation
            pinView.pinColor = MKPinAnnotationColorGreen;

            NSLog( @"data from ann index %@", annTile);
        }
        if([[annotation title] isEqualToString:@"Louisa's"])
        {
            // Do somethingMKAnnotation
            pinView.pinColor = MKPinAnnotationColorGreen;

            NSLog( @"data from ann index %@", annTile);
        }


        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;

        UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView = rightButton;
    } else {
        pinView.annotation = annotation;
    }
    return pinView;
}


I am then using the function below to filter my pins locaions



-(void)FilterAddAll:(id)sender
{
    [mapview removeAnnotations:annoArra];
    [mapview removeAnnotations:annoArrayVenue];
 [mapview removeAnnotations:artArray];


//    CLLocationCoordinate2D center = mapview.centerCoordinate;
//    mapview.centerCoordinate = center;


    [mapview addAnnotations:annoArra];
    [mapview addAnnotations:annoArrayVenue];
    [mapview addAnnotations:artArray];

}

-(void)FilterArt:(id)sender
{
    [mapview removeAnnotations:annoArra];
    [mapview removeAnnotations:artArray];
    [mapview removeAnnotations:annoArrayVenue];

    [mapview addAnnotations:annoArra];
}

-(void)FilterVenue:(id)sender
{
    [mapview removeAnnotations:annoArra];
    [mapview removeAnnotations:artArray];
    [mapview removeAnnotations:annoArrayVenue];

    [mapview addAnnotations:artArray];
}

The Question: How do I get the pin colors to retain their original color ? After I filter they come back as random pin colors.

Thanks again.

  • 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-16T13:04:37+00:00Added an answer on June 16, 2026 at 1:04 pm

    This occurs because you’re not using the “reuseIdentifier” properly. When you get back a pin from dequeueReusableAnnotationViewWithIdentifier:@”pinView”, you need to either:

    always set the pin color, OR
    use a different reuseIdentifier for each colored pin

    i.e. you might be getting a reusable view with a red pin, and you want to display a blue pin

    example:

    MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
        if (!pinView) {
    
            //////////////
            pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
    
            pinView.animatesDrop = YES;
            pinView.canShowCallout = YES;
    
            UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            pinView.rightCalloutAccessoryView = rightButton;
        } else {
            pinView.annotation = annotation;
        }
    
    // SET THE PIN COLOR REGARDLESS OF WHETHER A REUSABLE ANNOTATION WAS RETURNED OR NOT
    
            pinView.pinColor = MKPinAnnotationColorGreen;
            if([[annotation title] isEqualToString:@"MuRoom"])
            {
                // Do somethingMKAnnotation
                pinView.pinColor = MKPinAnnotationColorRed;
    
                NSLog( @"data from ann index %@", annTile);
            }
            if([[annotation title] isEqualToString:@"Mike's"])
            {
                // Do somethingMKAnnotation
                pinView.pinColor = MKPinAnnotationColorRed;
    
                NSLog( @"data from ann index %@", annTile);
            }
            if([[annotation title] isEqualToString:@"Bill's"])
            {
                // Do somethingMKAnnotation
                pinView.pinColor = MKPinAnnotationColorPurple;
    
                NSLog( @"data from ann index %@", annTile);
            }
            if([[annotation title] isEqualToString:@"Steve's"])
            {
                // Do somethingMKAnnotation
                pinView.pinColor = MKPinAnnotationColorGreen;
    
                NSLog( @"data from ann index %@", annTile);
            }
            if([[annotation title] isEqualToString:@"Louisa's"])
            {
                // Do somethingMKAnnotation
                pinView.pinColor = MKPinAnnotationColorGreen;
    
                NSLog( @"data from ann index %@", annTile);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am trying to create a stacked barplot using the following code: test
Hello Friends I am using the following code to show the amount entered in
Hello in my aspx page using MVC 3, I have the following code: <%Response.WriteFile(/Content/Bing.htm);
Currently we are using the following code in .htaccess to redirect users from mydomain.com
Hello and thanks in advance for the help. I am having an issue when
Hello I am following a rails tutorial, I am using rails 3.2.3 and I
Hello all and thanks for any help in advance. I have a ruby on
i am using following code to show google map and also create a marker
Hello friends following is my code HTML <ul class=menu-item> <li>item</li> <li>item</li> <li>item</li> </ul> CSS
Hello and thanks in advance for the help. I have a sql table hosted

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.