I have been scratching my head for a while on this one. I couldn't find any solution so far, so I decided to create a question. I appreciate the help.
My problem:
My table view header gets into delete mode with no value, when I try to delete any arbitrary cell in my table view and gets removed along with the cell that I am deleting. I am not using a reusable cell and I am not sure what causing this problem.
This is what the table view header currently looks like:
And This is what I want to achieve:
As for the code:
This is how I am setting my table view header:
- (void)viewDidLoad
{
[super viewDidLoad];
self.containerTableView.allowsMultipleSelectionDuringEditing = NO;
if (self.isCorrectDataType)
{
UITableViewCell *cell = [[UITableViewCell alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 44)];
cell.backgroundColor = [UIColor blackColor];
self.containerTableView.tableHeaderView = cell;
}
}
This is how I am enabling the editing mode and deleting a cell:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return [self.data count] > 0 ? YES : NO;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.data removeObjectAtIndex:indexPath.row];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.data];
[self.defaults setObject:data forKey:@"userContent"];
[self.defaults synchronize];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}