views:

190

answers:

1

hello genius and nerds

I have a TableViewCell with a UISwitch in accessoryView. I don't want that blue background if someone selected it. There fore i used

cell.userInteractionEnabled = NO;

but then the whole cell isnt accessable so i tried that

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

i think this wont work because cell is the parent of the accessoryView. but how can i manage this issue ? A hint in the right direction would be great.

Simon

Here is the complete cellForRowAtIndexPath method:

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;
+1  A: 

Try this in your cellForRowAtIndexPath method:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

You also have the option of using this in your didSelectRowAtIndexPath method:

[table deselectRowAtIndexPath:indexPath animated:NO];
alku83
thanks great exactly what ive searched for :-)
Simon
no probs, you're welcome!
alku83