繁体   English   中英

UITableViewCell没有userInteraction,但在cell.accessoryView上

[英]UITableViewCell no userInteraction but on cell.accessoryView

我在附件视图中有一个带有UISwitch的TableViewCell。 如果有人选择它,我不想要蓝色背景。 我曾经使用过

cell.userInteractionEnabled = NO;

但后来整个单元格都无法访问,所以我试过了

cell.userInteractionEnabled = NO;
cell.accessoryView.userInteractionEnabled = YES;

我认为这不会工作,因为cell是accessoryView的父级。 但我该如何处理这个问题呢? 正确方向的提示会很棒。

西蒙

这是完整的cellForRowAtIndexPath方法:

cell.textLabel.text = @"dasda";
cell.userInteractionEnabled = NO;
cell.accessoryType = UITableViewCellAccessoryNone;

UISwitch *mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
mySwitch.tag = row;
[cell addSubview:mySwitch];
cell.accessoryView = mySwitch;
cell.accessoryView.userInteractionEnabled = YES;

[(UISwitch *)cell.accessoryView setOn: YES];
[(UISwitch *)cell.accessoryView addTarget:self action:@selector(someAction:) forControlEvents:UIControlEventValueChanged];

return cell;

在你的cellForRowAtIndexPath方法中尝试这个:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

您还可以选择在didSelectRowAtIndexPath方法中使用它:

[table deselectRowAtIndexPath:indexPath animated:NO];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM