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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:13:48+00:00 2026-06-09T18:13:48+00:00

I have been poking around with the MKMapView for quite some time trying to

  • 0

I have been poking around with the MKMapView for quite some time trying to get more familiar with it and I ran into a problem.

I have my MapView populated with two pins and when I pressed them they have their respective annotations. I also have a button that will take me to a new UIView with UlLabels that will be loaded with data from an array.

Looking at my console I notice that the data is coming through but instead of it being just for the pin I selected its loading all of them and then displaying the last one.

Here is my code for the method I’m using to load the data for the next view:

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

   MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:addAnnotation     reuseIdentifier:@"currentloc"];
    if(annView.tag = 0) {
            GSStore * theStore = [globalCMS getStoreById:1];
            NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
            int storeid = theStore.storeid;
            [prefs setInteger:storeid forKey:@"selectedstore"];

            NSLog(@"%@", theStore.name);

            storeName.text = [NSString stringWithFormat:@"%@", theStore.name];
            storeCS.text = [NSString stringWithFormat:@"%@,%@", theStore.city, theStore.state];
            storeHours.text = [NSString stringWithFormat:@"%@", theStore.hours];
            storePhone.text = [NSString stringWithFormat:@"%@", theStore.phone];
            storeAddress.text = [NSString stringWithFormat:@"%@", theStore.address];
            storeCSZ.text = [NSString stringWithFormat:@"%@,%@ %@", theStore.city, theStore.state, theStore.zip];
            storeWebsite.text = [NSString stringWithFormat:@"%@", theStore.website];
            }
    if(annView.tag = 1){
            GSStore * theStore = [globalCMS getStoreById:2];
            NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
            int storeid = theStore.storeid;
            [prefs setInteger:storeid forKey:@"selectedstore"];

            NSLog(@"%@", theStore.name);

            storeName.text = [NSString stringWithFormat:@"%@", theStore.name];
            storeCS.text = [NSString stringWithFormat:@"%@,%@", theStore.city, theStore.state];
            storeHours.text = [NSString stringWithFormat:@"%@", theStore.hours];
            storePhone.text = [NSString stringWithFormat:@"%@", theStore.phone];
            storeAddress.text = [NSString stringWithFormat:@"%@", theStore.address];
            storeCSZ.text = [NSString stringWithFormat:@"%@,%@ %@", theStore.city, theStore.state, theStore.zip];
            storeWebsite.text = [NSString stringWithFormat:@"%@", theStore.website];  
            }

    if (annView.tag = 2) {
            GSStore * theStore = [globalCMS getStoreById:3];
            NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
            int storeid = theStore.storeid;
            [prefs setInteger:storeid forKey:@"selectedstore"];

            NSLog(@"%@", theStore.name);

            storeName.text = [NSString stringWithFormat:@"%@", theStore.name];
            storeCS.text = [NSString stringWithFormat:@"%@,%@", theStore.city, theStore.state];
            storeHours.text = [NSString stringWithFormat:@"%@", theStore.hours];
            storePhone.text = [NSString stringWithFormat:@"%@", theStore.phone];
            storeAddress.text = [NSString stringWithFormat:@"%@", theStore.address];
            storeCSZ.text = [NSString stringWithFormat:@"%@,%@ %@", theStore.city, theStore.state, theStore.zip];
            storeWebsite.text = [NSString stringWithFormat:@"%@", theStore.website];  
            }

}
  • 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-09T18:13:50+00:00Added an answer on June 9, 2026 at 6:13 pm

    Just to explain why you are seeing “the method loading all the data”:

    The if conditions are using a single equals (=) sign instead of a double (==).
    The single = is an assignment while the double == is the one for checking equality.

    Since the assignment executes successfully in all the ifs, the code inside all the ifs executes.

    However, the real problem is that you are creating a new instance of an annotation view in the didSelectAnnotationView delegate method which is not what you want.

    Instead of creating a new instance, you can use the annotation view instance that the method is providing you as a parameter (ie. view).

    So theoretically you could look at view.tag.

    But I would highly recommend not relying on tags and instead placing all the data you need for an annotation in the annotation class itself. Then you can access the annotation in this method using view.annotation and casting it to your custom class to access custom properties:

    MyAnnotationClass *myAnn = (MyAnnotationClass *)view.annotation;
    NSLog(@"myAnn.someCustomProperty = %@", myAnn.someCustomProperty);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, so I've been doing some poking around, and I realize my problem, but
I have been using TortoiseSVN for some time and I really like it. I
I have been poking around and have been unable to find a standard for
I am poking at XBRL documents trying to get my head around how to
I've been poking around with R graphical parameters trying to make my plots look
I have been poking around for a recipe / example to index a list
I have been poking around in PHP for OOP and I noticed something... Objects
Have been trying to encrypt an xml file to a string so that I
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
Have have been trying to make a validator for my xml files. I have

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.