I have a mapview controller which shows pins from an array of business objects I have created (each business has a method to get the title and subtitle of the pin).
I have added a disclosure button to each pin annotation which works correctly, but I am not sure how to pass a variable to the detail view which is to be loaded from the disclosure button, and show all the details for that particular business.
I add my businesses to the array like this (in viewWillAppear)...
// fetch model data for table view
SGTGAppDelegate *appDelegate = (SGTGAppDelegate *)[[UIApplication sharedApplication] delegate];
self.businesses = appDelegate.vaBusinesses;
// Add the business to the map
[self.mapView addAnnotations:self.businesses];
I then format the annotations like this...
-(MKAnnotationView *)mapView:(MKMapView *)amapView viewForAnnotation:(id<MKAnnotation>)annotation{
static NSString *PinIdentifier = @"PinIdentifier";
//Use default style for user location
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
//Obtain a pin
MKPinAnnotationView *pin = (MKPinAnnotationView *) [amapView dequeueReusableAnnotationViewWithIdentifier:PinIdentifier];
if (pin == nil){
pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:PinIdentifier] autorelease];
}
UIButton * detailView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// Configue the pin
pin.annotation = annotation;
pin.animatesDrop = NO;
pin.pinColor = MKPinAnnotationColorRed;
pin.rightCalloutAccessoryView = detailView;
pin.canShowCallout = YES;
return pin;
}
I then have this method to handle the disclosure button but not sure what do here to get an id of the business to pass onto the detail view...
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"annotation %@", view.annotation[0]);
// Fetch the businesses for this row
// not sure what to do here
//SGTGVABusiness *business = [self.businesses objectAtIndex:[view.annotation]];
// Show the detail view by pushing it onto the navigation stack
SGTGVADetailViewController *dvc = [[SGTGVADetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
//dvc.business = business;
[self.navigationController pushViewController:dvc animated:YES];
[dvc release];
}