Luciano
Luciano

Reputation: 1238

UITableView insertRowsAtIndexPaths remove cell separator

I need to add a new row under the selected row. I'm using this code in didSelectRowAtIndexPath:

[_dataSource insertObject:newDataObject atIndex:indexPath.row + 1];

NSMutableArray *indexPaths = [NSMutableArray array];
NSInteger currentCount = indexPath.row;
[indexPaths addObject:[NSIndexPath indexPathForRow:currentCount+1 inSection:0]];

[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

It adds the new row in the correct position, but it also deletes the upper cell separator of the selected row. What am I doing wrong?

Upvotes: 2

Views: 599

Answers (1)

storoj
storoj

Reputation: 1867

Seems like UITableViewCell has no separator in selected state. UITableViewCellSelectionStyleNone just disables highlighting, but cell is selected anyway. adding

   [tableView beginUpdates];
   // insert/delete manipulations
   [tableView deselectRowAtIndexPath:indexPath animated:NO];
   [tableView endUpdates];

fixes the problem

Upvotes: 3

Related Questions