I often need to set table view cells to their original selected state, for which I use the following code:
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; [cell setSelected:YES]; cell.accessoryType = UITableViewCellAccessoryCheckmark;
I am using selectRowAtIndexPath:indexPath and setSelected:YES at the same time because I do not quite understand which of the two methods is the preferred way to programmatically select the cell.
Which statement should be used and why?
Alexr
source share