phi phi -4 years ago 93
iOS Question

Why is -didDeselectRowAtIndexPath not being called?

I created a fresh project (Xcode 4, Master-Detail application) just to see if I'm doing something wrong, but I still have the same problem. I want to call

when the user deselects a cell, so this is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"%s", __PRETTY_FUNCTION__);

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%s", __PRETTY_FUNCTION__);
[tableView reloadData];

-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%s", __PRETTY_FUNCTION__);
return indexPath;

The problem is that
don't seem to be called. Is this the expected behavior? The docs for

Tells the delegate that the specified row is now deselected.

so I guess that it should work as I thought.

Answer Source

the documentation of tableView:willDeselectRowAtIndexPath: also says that

This method is only called if there is an existing selection when the user tries to select a different row. The delegate is sent this method for the previously selected row. You can use UITableViewCellSelectionStyleNone to disable the appearance of the cell highlight on touch-down.

It not worked for we when I used UITableViewCellSelectionStyleNone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download