gpt4 book ai didi

iphone - 如何在 map 注释 View 中找出引脚 ID?

转载 作者:太空狗 更新时间:2023-10-30 03:52:55 24 4
gpt4 key购买 nike

如何找出被点击的图钉的图钉 ID(即图钉标题和副标题的详细信息)?

我用这个来显示引脚注释。这段代码在 View 中确实加载了:

[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];
}
}

在委托(delegate)中:

- (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 是新的类对象。

最佳答案

当注释获取选定的 map View 时调用其委托(delegate)中的 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
}
}

如果你想获得配件控制的 Action 点击使用

-(void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// get annotation details here.
}

关于iphone - 如何在 map 注释 View 中找出引脚 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5947188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com