2
我想单击注解的详细按钮时执行详细视图。但是每个引脚必须具有不同的细节视图。要做到这一点,我尝试设置标签按钮。然后我会在calloutAccessoryControlTapped方法中使用这个标签来添加它们的详细视图。我的代码如下。但它停在for循环。我该如何解决这个问题?如何获取UIButtonTypeDetailDisclosure在目标c中单击的注释?
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
static NSString *annReuseId = @"test";
MKPinAnnotationView *annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annReuseId];
if (annView == nil)
{
annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annReuseId];
annView.animatesDrop = YES;
annView.canShowCallout = YES;
[annView setSelected:YES];
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView=detailButton;
for (int i=0; i<=[[mapView annotations] count]; i++)
{
detailButton.tag =[[[mapView annotations] objectAtIndex: i] integerValue];
NSLog(@"button %i",detailButton.tag);
}
}
else {
annView.annotation = annotation;
}
return annView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"calloutAccessoryControlTapped: annotation = %@", view.annotation);
RestaurantsView *detailView=[[RestaurantsView alloc] initWithNibName:@"RestaurantsView" bundle:nil];
//here, can set annotation info in some property of detailView
// [[self navigationController] pushViewController:detailView animated:YES];
// [detailView release];
[self.view addSubview:detailView.view];
}
nslog消息是calloutAccessoryControlTapped:annotation =什么是是什么意思? –
2012-02-09 07:37:33
我怎么知道点击了哪个按钮? – 2012-02-09 07:40:13
'MKUserLocation'是系统为用户位置提供的注释(蓝点)。我不知道你是否有意或无意,但是你的'viewForAnnotation:'把这个蓝点变成红色的针。我建议你阅读[文档](https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html)以及参考[Apple的示例代码] (https://developer.apple.com/library/ios/#samplecode/MapCallouts/Listings/MapViewController_m.html) – 2012-02-09 08:10:35