how to toggle the selection color of a UITableViewCell?
I want to modify a cell in a table view; making it highlight blue only when clicked. when released, the blue color should disap开发者_运维知识库pear.
the code:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
in the configuration of the cell, will disable the selection completely.
in all, this is mostly needed when i return from the push view controller. i then dont want to see any selected cells in the table. Any ideas on how to do this? thanks
When you touch a row in a tableview (if selection is allowed) the row is rendered in the selection style. If you want the "blue" selection colour to disappear, just deselect the row using:
NSIndexPath* rowPath = [NSIndexPath indexPathForRow:5 inSection:2];
[self.tableView deselectRowAtIndexPath:rowPath animated:NO];
Sounds like you're detecting the selection and doing something with the object backing the row and then returning to the same table, so just do the deselection in the same method as you do the action probably in:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
You can set a cell background color when the user clicks and set it back to white when the user releases.
That code should be useful to solve the 2nd problem
self.clearsSelectionOnViewWillAppear = NO;
精彩评论