UITutton在UITableViewCell中

时间:2013-06-25 06:27:36

标签: ios cocoa-touch uitableview uibutton

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

My Custom Cell

黑色大纲是单元格(UITableViewCell *),它由' cellForRowAtIndex '返回。 此单元格包含“ myCustomCell ”作为子视图。 ' myCustomCell '有两个UIButton和以下属性:

    backgroundcolor = clearColor 
    opaque = NO

单击单元格中除两个红色框(UI按钮)之外的任何位置,我希望触发“ didSelectRowAtIndexPath ”。 但是如果用户点击UIButton,则只需触发目标选择器,而不是'didSelectRowAtIndexPath'。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:8)

如果您按上面提到的那样构建单元格: myCustomCell 表示单元格内的子视图,其中有两个按钮,每个按钮都有动作,这应该如下所示;单击按钮时, didSelectRowAtIndexPath 将不起作用,按钮将处理触摸事件,因为触摸层次结构将由第一个动作观察到,并且不会继续到didSelectRowAtIndexPath以及何时你选择 didSelectRowAtIndexPath 按钮以外的每个地方都会处理触摸,因为没有观察者处理这个触摸事件,它会到达 didSelectRowAtIndexPath