我有一个 mapview 控制器,它显示来自我创建的一系列业务对象的引脚(每个业务都有一个获取引脚标题和副标题的方法)。
我为每个正常工作的 pin 注释添加了一个披露按钮,但我不确定如何将变量传递到要从披露按钮加载的详细视图,并显示该特定业务的所有详细信息。
我将我的业务添加到这样的数组中(在 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];
}