views:

101

answers:

3

I have this code [tableView deselectRowAtIndexPath:indexPath animated:YES];

Why doesn't the table view deselect the row, What am i doing wrong.

EDIT:

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

}
A: 

A couple ideas:

  1. Use NSLog to troubleshoot the value of indexPath
  2. Make sure your tableView is wired up to the view controller in Interface Builder
Alex Reynolds
A: 

If your trying to stop your users from being able to select a row in your table view, this is the code you need:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    return nil;
}
s1mm0t
+3  A: 
-(void)tableView:(UITableView*)tableView didDeselectRowAtIndexPath:(NSIndexPath*)path {
//------------------------------------------^^^^^^^^
// huh?
  [tableView deselectRowAtIndexPath:path animated:YES];
}

The …didDeselect… method is called only when the cell is already deselected. But you want to deselect that cell only after it's already deselected... sounds strange? Perhaps you mean …didSelect…?

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)path {
//------------------------------------------^^^^^^
// yay.
  [tableView deselectRowAtIndexPath:path animated:YES];
}
KennyTM
oh thnx, my bad, was looking fot didSelect... Typo!