检测子视图上的UIButton触摸 [英] Detecting UIButton touches on a subview

查看:85
本文介绍了检测子视图上的UIButton触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个包含UIButton控件的子视图.该子视图以编程方式添加到其父视图中.点击此按钮时,我需要执行一个操作,但是由于它包含在其自己的子视图中,因此我无法将IBAction挂接到视图控制器上以推送另一个视图控制器.

I have added a subview which contains a UIButton control. This subview is added to its superview programatically. I need to perform an action when this button is tapped, but since it's contained within its own subview, I can't hook an IBAction up to the view controller in order to push another view controller.

是否有一种简便的方法来检测按钮是否被点击并在其超级视图中调用方法?

Is there an easy way to detect that the button is tapped and call a method within its super view?

推荐答案

您可以通过编程方式进行所有操作:

You can do everything programmatically:

[buttonName addTarget:self action:@selector(methodName:) forControlEvents:UIControlEventTouchUpInside];

然后创建您的方法:

- (void)methodName:(id)sender
{
     // Do something.
}

这就是您要做的全部代码.

This is all you have to code.

这篇关于检测子视图上的UIButton触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆