点击自定义注释并执行相应的功能

时间:2013-09-06 07:14:29

标签: ios objective-c uigesturerecognizer mkannotationview

我尝试实现点击自定义注释,当点击它时,表格中的行将突出显示,

我尝试将手势识别器添加到自定义注释中,但它不起作用。

我alsa尝试过注释做了select方法,结果是一样的。

我的代码如下;

   UITapGestureRecognizer *singlePress =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSinglePress:withIndex:temp:)];

    [annotationView addGestureRecognizer:singlePress];

    [annotationView setUserInteractionEnabled:YES];

1 个答案:

答案 0 :(得分:1)

在annotationView上添加callout按钮,例如

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
myCustomAnnotationView.rightCalloutAccessoryView = rightButton;

并致电方法

-(void)showDetails:(UIButton *) calOutBtn
{
   // do your stuff;
}

<强>编辑:

在你的情况下你需要添加像

这样的东西
UITapGestureRecognizer *gestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TouchViewMethod:)];
gestureRec.numberOfTouchesRequired = 1;
gestureRec.numberOfTapsRequired = 1;
[ annotationView addGestureRecognizer:gestureRec];