我正在使用MKMapView对象,并且能够创建引脚并将它们放置在地图上。我现在想要做的是从引脚获取信息。例如在我的如何从iOS中的地图引脚获取位置
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation (id<MKAnnotation>)annotation
我创建我的针脚并将其设置在地图上。我也正在创建按钮以供用户点击该引脚时使用。所有这一切都很好,很好。现在我的问题是,当按钮被点击时,我如何从点击的引脚获取信息?以下是我目前如何设置的一小段示例代码。任何建议将不胜感激。
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"location"];
annView.pinColor = MKPinAnnotationColorRed;
annView.animatesDrop = YES;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
UIButton* callout = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[callout addTarget:self action:@selector(loadDetails:) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = callout;
return annView;
}
- (void)loadDetails:(id)sender
{
//TODO: Get pin coordinates or address and match it back to an array of available address to show details in a new view
}
任何意见是极大的赞赏
这对我来说很好。唯一的问题是我有这个还必须创建按钮吗?我觉得如果按钮没有被设置或者其他任何东西都是浪费的。 – Seb 2012-04-16 20:43:58
我认为你必须使用'[UIButton buttonWithType:UIButtonTypeDetailDisclosureDisclosure]'来创建一个按钮,但是你不必设置一个目标/动作。它在表格视图中的设置与详细披露不同。尝试它并在这里评论回来,如果它的工作。 – 2012-04-16 20:54:07
只需创建按钮并设置标注即可。再次感谢你。 – Seb 2012-04-16 20:55:37