如何识别哪个引脚被窃听
我在这张地图上有一个MKMapView
和大量的针脚的应用程序。
每个引脚都得到了rightCalloutAccessoryView
。 我以这种方式创build它:
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside]; pinView.rightCalloutAccessoryView = rightButton;
我应该怎么知道,哪个针被窃听? 日Thnx
在showDetails:
方法中,您可以从地图视图的selectedAnnotations
数组中获取引脚。 即使该属性是NSArray
,只需获取数组中的第一个项目,因为地图视图只允许一次select一个引脚:
//To be safe, may want to check that array has at least one item first. id<MKAnnotation> ann = [[mapView selectedAnnotations] objectAtIndex:0]; // OR if you have custom annotation class with other properties... // (in this case may also want to check class of object first) YourAnnotationClass *ann = [[mapView selectedAnnotations] objectAtIndex:0]; NSLog(@"ann.title = %@", ann.title);
顺便说一句,而不是做addTarget
和实现一个自定义的方法,你可以使用地图视图的calloutAccessoryControlTapped
委托方法。 点击的注释在view
参数中可用:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { NSLog(@"ann.title = %@", view.annotation.title); }
如果使用calloutAccessoryControlTapped
请确保从viewForAnnotation
删除calloutAccessoryControlTapped
。
- 在为每个UITableViewCell设置高度后获得UITableViewCell的高度
- 来自xcode的iOS运行应用程序向我显示启用调试日志记录的消息
- IOS RESTKIT HTTP PUT示例
- 如何使用AFIncrementalStore在每个请求中添加一个Auth令牌?
- 在我的iOS应用程序中configurationAmazon Mobile Analytics和AWS Cognito引发了一些与IAM链接的exception
- UIButton背景颜色突出显示/select状态问题
- 无法确定何时UIImageView帧是平等的
- cellForRowAt不使用reloadData()方法调用indexPath
- 在XCode中使用-Objc标志给出Mach-O链接器错误