當標籤附件按鈕時,我需要傳遞itemId,所以我可以識別要傳遞到我的詳細信息視圖的項目。傳遞id到calloutAccessoryControlTapped
到目前爲止:
添加註釋:
for (id row in self.detailItem) {
Item *i = (Item *) row;
CLLocationCoordinate2D destination;
destination.latitude = (double) i.latitude;
destination.longitude = (double) i.longitude;
//i.itemid
MapViewAnnotation *destinationAnnotation = [[MapViewAnnotation alloc] initWithTitle: i.name andCoordinate: destination];
[self.mapView addAnnotation: destinationAnnotation];
[destinationAnnotation release];
}
添加附件按鈕
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinAnnotation == nil)
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinAnnotation.canShowCallout = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
return pinAnnotation;
}
找到該項目通過詳細視圖
-(void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// get annotation details here.
NSLog(@"%@", control);
}
你能否提供詳細介紹MapViewAnnotation。我需要MapViewAnnotation.h&MapViewAnnotation.m的內容 –