- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想在单击注释的详细信息按钮时进行详细 View 。但是每个引脚必须有不同的细节 View 。为此,我尝试将标签设置为按钮。然后我将在 calloutAccessoryControlTapped 方法中使用这个标签来添加它们的详细 View 。我的代码如下。但是它在 for 循环中停止了。我该如何解决这个问题?
- (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];
}
最佳答案
您不需要设置详情按钮的标签
。您可以删除 viewForAnnotation:
中的整个 for
循环。如果您想访问 calloutAccessoryControlTapped:
中的注释,只需使用 view.annotation
就像您对 NSLog(@"calloutAccessoryControlTapped: annotation = %@", view.annotation);
.
如果你真的需要索引,那么使用 [mapView.annotations indexOfObject:view.annotation]
但要小心,因为该数组还可能包含所有其他类型的注释,例如 MKUserLocation
.
关于objective-c - 如何获取在 objective-c 中单击了哪个注释 UIButtonTypeDetailDisclosure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9206812/
是否可以将 UIButtonTypeDetailDisclose 的图像从默认图像更改为更有趣的图像。但是,请注意,我要求的是按钮,而不是一种类型的 uibutton。 最佳答案 您必须更改单元格的a
我已将 UIButtonTypeDetailDisclosure 的图像更改为下图,但问题是图像变成了蓝色。我的问题在哪里? - (MKAnnotationView *)mapView:(MKMapV
我添加了annotaion pin point to my application ,当用户单击图钉时,会出现带有蓝色箭头的弹出窗口 (UIButtonTypeDetailDisclosure)。现在
我有一个自定义按钮类: CustomButton.h 文件: @interface CustomButton : UIButton @property (nonatomic, retain) NSSt
我正在尝试将 UIButtonTypeDetailDisclosure 添加到 View 的底部栏。 应用程序构建成功,但在运行时出现以下错误: *** Terminating app due to
我想在单击注释的详细信息按钮时进行详细 View 。但是每个引脚必须有不同的细节 View 。为此,我尝试将标签设置为按钮。然后我将在 calloutAccessoryControlTapped 方法
我是一名优秀的程序员,十分优秀!