表格单元格内的按钮不可点击 [英] Button inside table cell not clickable

查看:38
本文介绍了表格单元格内的按钮不可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义单元格,它有两个连接到它的方法的按钮.我将单元格添加到表格中,如下所示:

I have a custom cell which has two buttons that are connected to it's methods. I add the cell to the table like this:

BSOrderedItemCell *cell = (BSOrderedItemCell *)[tableView dequeueReusableCellWithIdentifier:@"OrderItemCell"];
if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"OrderItemCell" owner:self options:nil];
    cell = (BSOrderedItemCell *)[nib objectAtIndex:0];
}

然后我设置它的属性.

单元格大小与表格的 heightForRowAtIndexPath 相同:并且没有任何单元格标签或按钮超出该大小.

The cell size is the same as table's heightForRowAtIndexPath: and none of the cells labels or buttons are outside that size.

问题是我可以选择单元格,但我无法点击按钮.就好像我在轻敲一个标签,什么也没有发生.所以我最终得到了这样的结果:

The problem is that I can select the cell, but I can't tap on the buttons. It's as if I'm tapping on a label, nothing happens. So I end up with something like this:

只是为了澄清事情.问题不在于按钮单击方法.这是我无法物理点击按钮,就像有什么东西挡住了它,或者它被某些控件禁用了.

Just to clarify things. The problem is not the button click methods. It's that I can't physically click the button, like there is something in the way of it, or it's disabled by some control.

推荐答案

你可以试试这个..

[cell.button addTarget:self action:@selector(buttonClicked:)  forControlEvents:UIControlEventTouchUpInside];

避免选择单元格:

Cell's xib -> Selection -> Set as None

这篇关于表格单元格内的按钮不可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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