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:
- Use
NSLog
to troubleshoot the value ofindexPath
- 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;
}
精彩评论