zontragon zontragon - 1 year ago 65
iOS Question

deselecting UITableViewCell

I'm calling a view controller from a table view. When I return back the caller view the table cell that I pressed before stays selected so that I couldn't select it again before selecting another cell.

I've added deselectRowAtIndexPath method like below but it didn't worked.

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

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ctrl = [storyboard instantiateViewControllerWithIdentifier:@"node"];
self.navigationController.navigationBarHidden = NO;
self.navigationController.navigationItem.hidesBackButton = NO;
[self.navigationController pushViewController:ctrl animated:YES];

Answer Source

didDeselectRowAtIndexPath is only called AFTER your row has already been deselected, so your call to deselectRowAtIndexPath is useless. Simply place this in your didSelectRowAtIndexPath to deselect it after tapping on it:

[tableView deselectRowAtIndexPath:indexPath animated:YES];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download