【发布时间】:2015-03-23 09:36:55
【问题描述】:
我在UITableViewCell 上有一个UIButton 如果我设置了
button.enabled = false;
...然后对该按钮的后续点击触发点击UITableViewCell。
如果按钮被禁用,那么如何确保点击它不会触发表格单元格点击?
【问题讨论】:
标签: ios uiresponder
我在UITableViewCell 上有一个UIButton 如果我设置了
button.enabled = false;
...然后对该按钮的后续点击触发点击UITableViewCell。
如果按钮被禁用,那么如何确保点击它不会触发表格单元格点击?
【问题讨论】:
标签: ios uiresponder
你可以这样做
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(!cell.btn.enable)
return;
}
【讨论】:
一种方法是不禁用按钮,而只是认识到相关按钮目前不会响应触摸事件并且什么都不做 在此按钮的处理程序中。
if( buttonIsActive )
{
// trigger whatever the button was intended to trigger
}
为此,您需要继承 UIButton 并添加属性 buttonIsActive。
如果你不那样做,我想你将不得不在不同的层次上处理那个事件(比如在 UITableViewCell 的处理程序中)或者完全转向手势识别(也就是选择)(参见 Praful Kadam 的回答)。
【讨论】: