簡體   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