Knowing which annotation is selected and accessing properties of it.
- by kevin Mendoza
So far my program can display a database of custom annotation views. Eventually I want my program to be able to display extra information after a button on the annotation bubble is clicked. Each element in the database has a unique entry Number, so I thought it would be a good idea to add this entry number as a property of the custom annotation. The problem I am having is that after the button is clicked and the program switches to a new view I am unable to retrieve the entry number of the annotation I selected.
Below is the code that assigns the entry Number property to the annotation:
for (id mine in mines)
{
workingCoordinate.latitude = [[mine latitudeInitial] doubleValue];
workingCoordinate.longitude = [[mine longitudeInitial] doubleValue];
iProspectAnnotation *tempMine = [[iProspectAnnotation alloc] initWithCoordinate:workingCoordinate];
[tempMine setTitle:[mine mineName]];
[tempMine setAnnotationEntryNumber:[mine entryNumber]];
}
[mines dealloc];
When the button on an annotation is selected, this is the code that initializes the new view:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
mineInformationController *controller = [[mineInformationController alloc] initWithNibName:@"mineInformationController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
}
and lastly is my attempt at retrieving the entryNumber property from the new view so that I can compare it to the mines database and retrieve more information on the array element.
iProspectFresno_LiteAppDelegate *appDelegate = (iProspectFresno_LiteAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray* mines = [[NSMutableArray alloc] initWithArray:(NSMutableArray *)appDelegate.mines];
for(id mine in mines)
{
if ([[mine entryNumber] isEqualToNumber: /*the entry Number of the selected annotation*/])
{
/* display the information in the mine object */
}
}
So how do I access this entry number property in this new view controller?