I am working on a project on which I have to preselect a particular cell.
I can preselect a cell using -willDisplayCell
, but I can\'t deselect it when t
In addition to setting the cell as selected, you also need to inform the tableView that the cell is selected. Add a call to -tableView:selectRowAtIndexPath:animated:scrollPosition:
to your willDisplayCell:
method: and you will be able to deselect it as normal.
- (void)tableView:(UITableView*)tableView
willDisplayCell:(UITableViewCell*)cell
forRowAtIndexPath:(NSIndexPath*)indexPath
{
AppDelegate_iPad *appDelegte = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];
if ([appDelegte.indexPathDelegate row] == [indexPath row])
{
// SELECT CELL
[cell setSelected:YES];
// TELL TABLEVIEW THAT ROW IS SELECTED
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
Be sure to use UITableViewScrollPositionNone to avoid odd scrolling behavior.