UITableViewCell UITableViewCellSelectionStyleGray
The style of selected cells.
typedef enum {
UITableViewCellSelectionStyleNone,
UITableViewCellSelectionStyleBlue,
UITableViewCellSelectionStyleGray
} UITableViewCellSelectionStyle;
Constants
UITableViewCellSelectionStyleNone
The cell has no distinct style for when it is selected.
UITableViewCellSelectionStyleBlue
The cell when selected has a blue background. This is the default value.
UITableViewCellSelectionStyleGray
Then cell when selected has a gray background.
Discussion of [UITableViewCell UITableViewCellSelectionStyleGray]
You use these constants to set the value of the selectionStyle property.
UITableViewCell UITableViewCellSelectionStyleGray example.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ((indexPath.row % 2) == 1) {
cell.backgroundColor = UIColorFromRGB(0xEDEDED);
cell.textLabel.backgroundColor = UIColorFromRGB(0xEDEDED);
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
else
{
cell.backgroundColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
}
if ((indexPath.row % 2) == 1) {
cell.backgroundColor = UIColorFromRGB(0xEDEDED);
cell.textLabel.backgroundColor = UIColorFromRGB(0xEDEDED);
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
else
{
cell.backgroundColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
}
Example of [UITableViewCell UITableViewCellSelectionStyleGray].
You have to just put this code into cellForRowAtIndexPath
For disable the cell select:(While Click the cell)
cell.selectionStyle = UITableViewCellSelectionStyleNone;
For enable the cell:(While Click the cell)
cell.selectionStyle = UITableViewCellSelectionStyleBlue;(By Default)
cell.selectionStyle = UITableViewCellSelectionStyleGray;
Note that a cell with selectionStyle = UITableViewCellSelectionStyleNone will still cause the UI to call didSelectRowAtIndexPath when touched by the user. To avoid this, do as suggested below and set
cell.userInteractionEnabled = NO;
instead. Also note you may want to set cell.textLabel.enabled = NO to grey out the item.
For disable the cell select:(While Click the cell)
cell.selectionStyle = UITableViewCellSelectionStyleNone;
For enable the cell:(While Click the cell)
cell.selectionStyle = UITableViewCellSelectionStyleBlue;(By Default)
cell.selectionStyle = UITableViewCellSelectionStyleGray;
Note that a cell with selectionStyle = UITableViewCellSelectionStyleNone will still cause the UI to call didSelectRowAtIndexPath when touched by the user. To avoid this, do as suggested below and set
cell.userInteractionEnabled = NO;
instead. Also note you may want to set cell.textLabel.enabled = NO to grey out the item.
UITableViewCell UITableViewCellSelectionStyleGray example.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setUserInteractionEnabled:NO];
if (indexPath.section == 1 && indexPath.row == 0)
{
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
[cell setUserInteractionEnabled:YES];
}
}
{
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setUserInteractionEnabled:NO];
if (indexPath.section == 1 && indexPath.row == 0)
{
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
[cell setUserInteractionEnabled:YES];
}
}