简体   繁体   中英

Randomly UITableViewCell getting dark black selection color

In my application I have several TaBleViews, on selection in these tableviews app navigates back and forth. Sometimes selecting a cell on any of the tableview turns the selection color from default gray to dark black, it happens on random basis means the cell which shows black once, shows gray other time. I don't know why it is happening, please do suggest what can be the reason for this. Is this an iOS bug?

The screenshots are as:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

It is not a bug, it is like a marker that the cell is selected.

If you dont want to .selectionStyle = UITableViewCellSelectionStyleNone and preserver the highlight gray color;

You have to deselect the cell then, like:

Obj-C

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

Swift

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
{
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

Try this

Select your table in storyboard Click on show the attribute inspector and deselect Show Selection on Touch option.

in your didSelectRowAtIndexPath method write

[tableView deselectRowAtIndexPath:indexPath animated:YES];

in your cellForRowAtIndexPath write

cell.selectionStyle = UITableViewCellSelectionStyleNone;

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM