如何在地图注释视图中找出 pin id? [英] How to find out pin id in map annotation view?
本文介绍了如何在地图注释视图中找出 pin id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能找到被点击的 pin 的 pin id(即 pin 标题和副标题的详细信息)?
How can I find out the pin id (i.e. the details of pin title and subtitle) of pin that was clicked?
我有这个来显示引脚注释.这段代码在视图中确实加载了:
I have this to show pins annotations. This code is in view did load:
[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] ;
}
记录捕获是新的类对象.
Where record catch is new class object.
推荐答案
当注解被选中时,地图视图调用其委托中的 mapView:didSelectAnnotationView:
方法,你可以重写它以获得你想要的.
When annotation gets selected map view calls mapView:didSelectAnnotationView:
method in its delegate, you can override this to get what you want.
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
MKAnnotation *selectedAnnotation = view.annotation // This will give the annotation.
if([selectedAnnotation.title isEqualToString:@"yourTitle"])
{
// Do something
}
}
如果你想获得附件控制的动作点击使用
If you want to get the action for accessory control click make use of
-(void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// get annotation details here.
}
这篇关于如何在地图注释视图中找出 pin id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文