Hello,
I have a mapview with a few pins on it. The pins are loading longitude and latitude from a plist. I've also added a detailview where you get more info about the pin that gets tapped. However my problem is that when I tap on a pin (discloseButton ofc) and get pushed to the detailview it's always the last items data that loads (from the plist). It doesn't matter which pin I tap.
For example:
item 1 - title: car
item 2 - title: ball
item 3 - title: book
item 4 - title: bicycle
So if I tap on pin nr 1 the title in the detailview is bicycle. If I tap on pin nr 2 the title in the detailview is bicycle and so on. Hope you get the point :)
(Sorry for the bad title couldn't come up with a better one.)
Thanks!
Here's some code if it helps:
RootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Map";
map.delegate = self;
cam = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"Cam"
ofType:@"plist"]];
double minLat = [[cam valueForKeyPath:@"@min.latitude"] doubleValue];
double maxLat = [[cam valueForKeyPath:@"@max.latitude"] doubleValue];
double minLon = [[cam valueForKeyPath:@"@min.longitude"] doubleValue];
double maxLon = [[cam valueForKeyPath:@"@max.longitude"] doubleValue];
MKCoordinateRegion region;
region.center.latitude = (maxLat + minLat) / 2.0;
region.center.longitude = (maxLon + minLon) / 2.0;
region.span.latitudeDelta = (maxLat - minLat) * 1.05;
region.span.longitudeDelta = (maxLon - minLon) * 1.05;
map.region = region;
for (NSDictionary *camDict in cam){
annotationTest = [[MyAnnotation alloc] initWithDictionary:camDict];
[map addAnnotation:annotationTest];
[annotationTest release];
}
}
// AnnotatioView
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
[annView setAnimatesDrop:YES];
[annView setCanShowCallout:YES];
[annView setSelected:YES];
[annView setUserInteractionEnabled: YES];
UIButton *discloseButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
[discloseButton addTarget: self action: @selector(showMyView:) forControlEvents: UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = discloseButton;
return annView;
}
//Push the detailView with some data
- (IBAction)showMyView:(id)sender {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detailViewController.title = annotationTest.title;
detailViewController.tempAdress = annotationTest.subtitle;
detailViewController.tempUrl = annotationTest.url;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}