作成したビジネス オブジェクトの配列からピンを表示する mapview コントローラーがあります (各ビジネスには、ピンのタイトルとサブタイトルを取得するメソッドがあります)。
正しく機能する各ピン アノテーションに開示ボタンを追加しましたが、開示ボタンから読み込まれる詳細ビューに変数を渡し、その特定のビジネスのすべての詳細を表示する方法がわかりません。
私は自分のビジネスをこのように配列に追加します (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];
次に、注釈を次のようにフォーマットします...
-(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;
}
次に、開示ボタンを処理するこのメソッドがありますが、詳細ビューに渡すビジネスの ID を取得するためにここで何をすべきかわかりません...
-(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];
}