When I add an accessoryView to a UITableViewCell like so:
cell.accessoryView = myTextField;
I have to set the cell userInteractionEnabled to YES. The problem is, I don’t want the cell’s interaction enabled to be YES, only the textField’s. I tried this:
cell.userInteractionEnabled = NO;
myTextField.userInteractionEnabled = YES;
but because the text field is a subview of the UITableViewCell, that doesn’t have the desired effect.
So my question is: how can I enable interaction with a UI element within a UITableViewCell without enabling interaction with the cell itself? i.e. when the user presses the cell, I don’t want it to turn blue, but I still want them to be able to edit the text within the text field.
You can achieve this by setting the selection style of the cell to none (in IB) or, in code,
cell.selectionStyle = UITableViewCellSelectionStyleNone;. There is no need to disable interaction on the cell.