shreyasva
shreyasva

Reputation: 13516

Table View in iPhone

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];

}

Upvotes: 0

Views: 542

Answers (3)

kennytm
kennytm

Reputation: 523704

-(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];
}

Upvotes: 4

s1mm0t
s1mm0t

Reputation: 6095

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;
}

Upvotes: 0

Alex Reynolds
Alex Reynolds

Reputation: 96974

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

Upvotes: 0

Related Questions