UIButton里面UITableViewCell [英] UIButton inside UITableViewCell

查看:124
本文介绍了UIButton里面UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在myCustomCell类中有2个UIButtons,它是UITableViewCell的子类。

I have 2 UIButtons inside a myCustomCell Class which is a subclass of UITableViewCell.

黑色轮廓是单元格(UITableViewCell * strong> cellForRowAtIndex 。
单元格包含 myCustomCell 作为子视图。 ' myCustomCell '有两个UIButtons和以下属性:

The black Outline is the cell (UITableViewCell *) which is returned by 'cellForRowAtIndex'. This cell contains 'myCustomCell' as a subview. 'myCustomCell' has two UIButtons and the following properties :

    backgroundcolor = clearColor 
    opaque = NO

点击单元格中除了两个红色框(UI按钮)将触发 didSelectRowAtIndexPath
但是如果用户点击UIButton,只需要触发目标的选择器,而不是'didSelectRowAtIndexPath'。如果您按照上面提到的方式构建单元格,则

On clicking anywhere in the cell except for the two Red Boxes(UI Buttons), I want the 'didSelectRowAtIndexPath' be triggered. But if the user clicks on the UIButton, only the selector for the target needs to be triggered, and not the 'didSelectRowAtIndexPath'. How can I achieve this ?

推荐答案

myCustomCell 代表一个子视图在单元格内,它有两个按钮里面,每个按钮都有动作,这应该工作如下:当你点击按钮 didSelectRowAtIndexPath 将不工作,按钮将处理触摸事件,因为触摸层次结构将被观察的第一个动作是按钮,将不会继续didSelectRowAtIndexPath和当除了 didSelectRowAtIndexPath 按钮处理触摸事件之前,除了按钮之外,您还可以选择每个按钮,因为没有观察者处理此触摸事件,它会到达 didSelectRowAtIndexPath

if you build the cell as you mentioned above : the myCustomCell represent a subview inside the cell and it has two buttons inside it, each button has action, this should work as following; when you click on the button the didSelectRowAtIndexPath will not work and the button will handle the touch event since the touch hierarchy will be observed by the first action wich is the button and will not continue to the didSelectRowAtIndexPath and when you tab every where except buttons the didSelectRowAtIndexPath will handle the touch since there no observer handle this touch event and it will reach the didSelectRowAtIndexPath

这篇关于UIButton里面UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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