如何找到被点击的引脚的引脚ID(即引脚标题和副标题的详细信息)?
我有这个来显示引脚注释。这段代码在视图中加载了:
[resultCoordinate addObjectsFromArray:[sqlClass return_Coordinate]];
if ([resultCoordinate count])
{
for (int i =0; i < [resultCoordinate count]; i++)
{
dict = [resultCoordinate objectAtIndex:i];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[dict objectForKey:@"Lati"] floatValue];
region.center.longitude = [[dict objectForKey:@"Longi"] floatValue];
region.span.longitudeDelta = 0.2f;
region.span.latitudeDelta = 0.2f;
NSString *fishName = [dict objectForKey:@"Fish"];
fishName = [fishName stringByAppendingString:@" "];
NSString *fishWeight = [dict objectForKey:@"Weight"];
fishWeight = [fishWeight stringByAppendingString:@" kg"];
fishName = [fishName stringByAppendingString:fishWeight];
MapAnnotation *ann = [[MapAnnotation alloc] init];
ann.title = fishName;
ann.subtitle = [dict objectForKey:@"DateTime"];
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
}
并在代表中:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
[defaultPinID release];
return pinView;
}
点击信息按钮:
-(void)infoButtonPressed:(id)sender
{
recordCatch = [[RecordCatchDetails alloc] initWithNibName:@"RecordCatchDetails" bundle:nil];
[self.view addSubview:recordCatch.view] ;
}
其中record catch是新的类对象。
答案 0 :(得分:4)
当注释在其委托中获得选定的地图视图调用mapView:didSelectAnnotationView:
方法时,您可以覆盖它以获得所需的内容。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
MKAnnotation *selectedAnnotation = view.annotation // This will give the annotation.
if([selectedAnnotation.title isEqualToString:@"yourTitle"])
{
// Do something
}
}
如果您想获得配件控制的操作,请单击“使用
”-(void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// get annotation details here.
}