0

我已将ui 按钮添加到 disclouser 按钮

并实现了选择器方法

但动作选择器不响应按钮为什么和做什么

//To add a discloser button to show route map
UIButton *detailBtn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.leftCalloutAccessoryView=detailBtn;
[detailBtn addTarget:self action:@selector(showRoute:) forControlEvents:UIControlEventTouchUpInside];
DisplayMap *ann=(DisplayMap *)annotation;
detailBtn.tag = ann.detailButtonTag;


UIButton *btnOnPopup=[[UIButton alloc] initWithFrame:CGRectMake(- 207, -6, 300, 43)];
btnOnPopup.backgroundColor = [UIColor whiteColor];
[btnOnPopup addTarget:self action:@selector(showRoute2:) forControlEvents:UIControlEventTouchUpInside];
btnOnPopup.tag = ann.detailButtonTag;
btnOnPopup.userInteractionEnabled = YES;
[detailBtn insertSubview:btnOnPopup aboveSubview:detailBtn];

选择器

[btnOnPopup addTarget:self action:@selector(showRoute2:) forControlEvents:UIControlEventTouchUpInside];

(第二个按钮 btnOnPopup)不起作用。

4

2 回答 2

1

btnOnPopup超出了detailBtn's 的范围,所以触摸甚至不会到达它。无论如何,向按钮添加按钮并不是一个很好的做法。将它添加到按钮的超级视图可能会更好一些(并且会使您的触摸工作,但您可能需要调整框架)

[detailBtn.superview insertSubview:btnOnPopup aboveSubview:detailBtn];
于 2013-08-19T13:18:17.483 回答
0

添加视图和点击手势识别器而不是按钮:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];
[singleTap setNumberOfTapsRequired:1];
[view addGestureRecognizer:singleTap];

...

[detailBtn addSubview:view];

...

- (void)tapGestureHandler:(UIGestureRecognizer *)gestureRecognizer
{
    // your code for tap handler is here
}
于 2013-08-19T13:24:12.737 回答