我使用UITapGestureRecognizer连接注释。 我想检测触摸。
if ([annotation isKindOfClass:[Annotation class]])
{
NSString * annotationIdentifier = @"UserAnnotationIdentifier";
CustomAnnotationView * customAnnotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!customAnnotationView)
{
customAnnotationView = [[CustomAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(calloutTapped:)];
[customAnnotationView addGestureRecognizer:tapGesture];
我使用代码底部,但它在编译中导致错误
-(void) calloutTapped:(id) sender {
id<MKAnnotation> annotation = ((MKAnnotationView*)sender.view).annotation;
错误:在__strong id
类型的对象上找不到属性视图答案 0 :(得分:0)
变化:
-(void) calloutTapped:(id) sender
为:
-(void) calloutTapped:(UITapGestureRecognizer *) sender
然后sender
将具有view
属性
或首先将sender
投放到UITapGestureRecognizer
正确施法:
-(void) calloutTapped:(id) sender {
UITapGestureRecognizer *tapGesture = (UITapGestureRecognizer *)sender;
MKAnnotationView *sendersView = (MKAnnotationView *)tapGesture.view;
id<MKAnnotation> annotation = sendersView.annotation;
}