Mike_NotGuilty
Mike_NotGuilty

Reputation: 2405

iPhone - UITableViewCell white after selected

How is it possible that my UITableViewCell (Static cells) after i selected it become white again? When i tap on it , it becomes grey and stays grey! It should be grey for a short time if i tap on it.

Thanks

EDIT

Normally when you tap on a UITableViewCell - the background color of the cell turns grey for a short time. But my problem is in my application, when i tap on the cell, the background color of the cell stays grey. And I don't know how to solve this problem.

Upvotes: 0

Views: 1209

Answers (3)

Ebin Joy
Ebin Joy

Reputation: 3219

1) Set following code to your tableview

tableView.allowsSelection = false

2) Also check the tableview cell is return correctly. Some times people accidentally return as below

   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    return UITableViewCell()
}

So here double check, you should return the created cell instead of tableviewCell instance

Upvotes: 1

Eli Whittle
Eli Whittle

Reputation: 1092

For Swift 2.0+

This tableview delegate method is called each time you tap a cell in the tableview, it will provide you the 'indexPath' the user tapped (which is essentially which cell the user tapped). In the body of this method simply deselect the tapped cell which will turn it back to its non-selected status.

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

Upvotes: 1

rmaddy
rmaddy

Reputation: 318944

You need to deselect the cell in the didSelectRowAtIndexPath method.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // do stuff

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

Upvotes: 2

Related Questions