开发者

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

}


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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜