Detecting UIButton touches on a subview

馋奶兔 提交于 2019-12-11 11:42:19

问题


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?


回答1:


You can do everything programmatically:

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

and then create your method:

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

This is all you have to code.



来源:https://stackoverflow.com/questions/14733144/detecting-uibutton-touches-on-a-subview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!