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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:41:07+00:00 2026-06-01T06:41:07+00:00

I’m working on an iPhone application that displays a list of galleries on a

  • 0

I’m working on an iPhone application that displays a list of galleries on a Map. The list of galleries comes from a plist which is downloaded from the web. The location coordinates are loading into the map correctly as well as the title and subtitle for each of the locations.

I am also able to load an image for the annotation view image from the plist.

The issue I’m having is that both the annotation view image and a detail view page load the information of the last location in the plist array rather than loading the information that corresponds to the correct location information.

I believe that the problem has to do with this integer:
for(int i=0; i < [galleries count]; i++)

but I’m honestly not sure.

Any help would be greatly appreciated!

Here is the code:

MapAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>

@interface MapAnnotation : NSObject <MKAnnotation>{

CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subTitle;

}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;

@end

MapAnnotation.m

#import "MapAnnotation.h"

@implementation MapAnnotation
@synthesize coordinate, title, subtitle;

@end

MapViewViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface MapViewViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>{

NSMutableArray *galleries;
MKMapView *_MapView;
MKAnnotationView *Ann;

}


@property (nonatomic, retain) IBOutlet MKMapView *_MapView;

@property (nonatomic, retain) IBOutlet MKAnnotationView *Ann;

@property (nonatomic, retain) NSArray *addressArray;

@property (nonatomic, retain) NSMutableArray *galleries;

@property (nonatomic, retain) NSString *imageUrl;

@property (nonatomic, retain) NSData *imagedata;


-(IBAction)getlocation;

- (void)loadAnnotations;


@end

MapViewViewController.m

#import "MapViewViewController.h"
#import "MapAnnotation.h"
#import "MoredetailViewController.h"


@implementation MapViewViewController
@synthesize _MapView, Ann;
@synthesize galleries, addressArray;
@synthesize imagedata, imageUrl;


- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

[galleries removeAllObjects];

addressArray=[[NSMutableArray alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://www.jimirobinson.com/plist/MapInformation.plist"]];    

galleries = [[NSMutableArray alloc] initWithArray:addressArray];

[self loadAnnotations]; 

}


- (void)viewDidLoad
{
[super viewDidLoad];

MKCoordinateRegion region;
region.center.latitude = 39.952133;
region.center.longitude = -75.144264;
region.span.longitudeDelta = 0.005;
region.span.latitudeDelta = 0.001;

[_MapView setRegion:region animated:YES];
}


-(IBAction)getlocation {
_MapView.showsUserLocation = YES;
}


- (void)loadAnnotations {

CLLocationCoordinate2D pinCoordinates;

for (int i = 0; i < [galleries count]; i++)
{

    MapAnnotation *myAnnotations = [[MapAnnotation alloc] init];

    pinCoordinates.latitude = [[[galleries objectAtIndex:i] objectForKey:@"latitude"] floatValue];
    pinCoordinates.longitude = [[[galleries objectAtIndex:i] objectForKey:@"longitude"] floatValue];
    [myAnnotations setTitle:[[galleries objectAtIndex:i] objectForKey:@"annotation_title"]];
    [myAnnotations setSubtitle:[[galleries objectAtIndex:i] objectForKey:@"annotation_subtitle"]];

    imageUrl = [[galleries objectAtIndex:i] objectForKey:@"map_pin_image_url"];
    imagedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];

    [myAnnotations setCoordinate:pinCoordinates];
    [_MapView addAnnotation:myAnnotations];

}

                    }


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

MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"AddrAnnot"];

annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"AddrAnnot"];

    if (_MapView.userLocation == annotation)
            {
            return nil;
            }

annotationView.image = [UIImage imageWithData:imagedata];          
annotationView.canShowCallout = YES;
[annotationView setBackgroundColor:[UIColor clearColor]];
[annotationView setFrame:CGRectMake(0, 0, 30, 30)];
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.leftCalloutAccessoryView =  [[UIImageView  alloc] initWithImage:[UIImage imageNamed:@"flag1.png"]];


[_MapView addAnnotation:annotation];
return annotationView;

NSLog(@"%s: annotationView=%@", __func__, annotationView);

}




- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{

MoredetailViewController *moredetail = [self.storyboard instantiateViewControllerWithIdentifier:@"TextPage"];
[self.navigationController pushViewController:moredetail animated:YES];


for(int i=0; i < [galleries count]; i++)        
{
    moredetail.MoredetailTitle.text = [[galleries objectAtIndex:i] objectForKey:@"annotation_title"];  

    moredetail.MoredetailDescription.text = [[galleries objectAtIndex:i] objectForKey:@"annotation_subtitle"];
    NSLog(@"%d", i);


    NSString *image = [[galleries objectAtIndex:i] objectForKey:@"map_pin_image_url"];  
    NSData *dataz = [NSData dataWithContentsOfURL:[NSURL URLWithString:image]];
    moredetail.detailImage.image = [UIImage imageWithData:dataz];
} 


NSLog(@"I've been tapped");

}



- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 

NSLog(@"%s: galleries=%@", __func__, galleries);

}


- (void)viewDidUnload
{
    [super viewDidUnload];
}


@end

MapInformation.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
    <key>title</key>
    <string>Gallery One</string>
    <key>annotation_title</key>
    <string>Gallery One Title</string>
    <key>annotation_subtitle</key>
    <string>Gallery One Subtitle</string>
    <key>map_pin_image_url</key>
    <string>http://www.jimirobinson.com/plist/flag1.png</string>
    <key>latitude</key>
    <real>39.952827</real>
    <key>longitude</key>
    <real>-75.145203</real>
</dict>
<dict>
    <key>title</key>
    <string>Gallery Two</string>
    <key>annotation_title</key>
    <string>Gallery Two Title</string>
    <key>annotation_subtitle</key>
    <string>Gallery Two Subtitle</string>
    <key>map_pin_image_url</key>
    <string>http://www.jimirobinson.com/plist/flag2.png</string>
    <key>latitude</key>
    <real>39.952184</real>
    <key>longitude</key>
    <real>-75.145368</real>
</dict>
<dict>
    <key>title</key>
    <string>Gallery Three</string>
    <key>annotation_title</key>
    <string>Gallery Three Title</string>
    <key>annotation_subtitle</key>
    <string>Gallery Three Subtitle</string>
    <key>map_pin_image_url</key>
    <string>http://www.jimirobinson.com/plist/flag3.png</string>
    <key>latitude</key>
    <real>39.951135</real>
    <key>longitude</key>
    <real>-75.143368</real>
</dict>
</array>
</plist>
  • 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-01T06:41:09+00:00Added an answer on June 1, 2026 at 6:41 am

    I’m afraid to say but this code needs lots of work in order to work as you expect.

    Firstly, imagedata is an instance variable, and you are setting it to be the image data of the last annotation (in loadAnnotations). viewForAnnotation then uses imagedata for the image, so it will always be set to the image for the last annotation.

    Secondly, in calloutAccessoryControlTapped you are iterating over all the galleries, and setting properties on the moredetail view controller, so that the view controller will always show detail for the last gallery.

    I suggest that you add more properties to your MapAnnotation class, such as imageUrl. You can then set this property when creating the annotations. In viewForAnnotation you can then do this:

    if ([annotation isKindOfClass:[MapAnnotation class]]) 
    {
          MapAnnotation *mapAnnotation = (MapAnnotation *)annotation;
          annotationView.image = [NSData dataWithContentsOfURL:[NSURL URLWithString:[mapAnnotation imageURL]];
    

    And in the calloutAccessoryControlTapped method you can do this:

    MapAnnotation *mapAnnotationPressed = (MapAnnotation *)view.annotation;
    moredetail.MoredetailTitle.text = [mapAnnotationPressed title];
    

    I hope this gives you some idea of how to get your code working.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.