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

  • Home
  • SEARCH
  • 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 8278021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:52:09+00:00 2026-06-08T08:52:09+00:00

Im writing a program in IOS where i mark a few spots on the

  • 0

Im writing a program in IOS where i mark a few spots on the map with a pin.
Now i have the dequereusableannotationview code that works fine with ONE pin but crashes with i use two pins or try to mark two points on the map.
IT only works when i either comment out ONE annotation or comment out the dequeucode
But the question is….do i even need that dequeue code? as the most pins i will ever have is probably…10..?

Thanks you

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

    MKMapView *mv=[[MKMapView alloc]initWithFrame:CGRectZero];
    mv.delegate=self;
    [self setView:mv];

    MapAnnotation* ann=[[MapAnnotation alloc]init];
    CLLocationCoordinate2D location;
    location.latitude=(double)51.501468;
    location.longitude=(double)-0.141596;
    [ann setCoordinate:location];
    [ann setTitle:@"test"];
    [ann setTitle:@"plz work"];
    [mv addAnnotation:ann];
    [ann release];

    MapAnnotation* AnnB=[[MapAnnotation alloc]init];
    CLLocationCoordinate2D locationB;
    locationB.latitude=(double)16.4944;
    locationB.longitude=(double)-151.7364;
    [AnnB setCoordinate:locationB];
    [AnnB setTitle:@"test"];
    [AnnB setSubtitle:@"work"];

    [mv addAnnotation:AnnB];
    [AnnB release];
}

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
    MKPinAnnotationView *pinView=nil;

    if (annotation!=mapView.userLocation) {
        static NSString *defaultID=@"MYLoction";

        pinView=(MKPinAnnotationView *)[mapView
                                        dequeueReusableAnnotationViewWithIdentifier:defaultID];
        if (pinView=nil) {
            pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultID]autorelease];

            pinView.pinColor=MKPinAnnotationColorPurple;
            pinView.canShowCallout=YES;
            pinView.animatesDrop=YES;
        }
    }
}
  • 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-08T08:52:10+00:00Added an answer on June 8, 2026 at 8:52 am

    One problem is that when you test for equality in

    if (pinView=nil) {
    

    you are using the assignment operator, =, instead of the equality operator, ==. This will cause nil to be assigned to pinView every time, so you will never reuse an annotation. I’m surprised the compiler didn’t catch this.

    Also, you aren’t actually returning anything in viewForAnnotation:. Try this instead:

    -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
        (id<MKAnnotation>)annotation {
        if(annotation == mapView.userLocation) {
            return nil;
        }
    
        static NSString *defaultID=@"MYLoction";
    
        MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView 
            dequeueReusableAnnotationViewWithIdentifier:defaultID];
    
        if (!pinView) {
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                reuseIdentifier:defaultID] autorelease];
    
            pinView.pinColor=MKPinAnnotationColorPurple;
            pinView.canShowCallout=YES;
            pinView.animatesDrop=YES;
        }
    
        return pinView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program to grade C++ code that students submit. Right now
I'm writing a moderately complex iOS program that needs to have multiple threads for
Im writing a program that should read input via stdin, so I have the
I am writing a program and have some code inside a string. This code
I am writing an iphone (IOS 4) program that capture live video from the
I have tried writing program that plays a sound file but have been unsuccessful
Hi there: I have been writing an iOS program which uses many http queries
I'm writing a program that handles DBs and writes any changes into ListView for
I am currently writing a program using Weka that builds a model (using one
I'm writing a program that's parsing an XML file to java objects using smooks.

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.