I have problem with deleting rows from my tableView, because I have multiple sections that are dynamically generated when view controller appears, so when I return the count in numberOfRowsInSection it ends up looking like this:
NSInteger count = [[_sectionsArray objectAtIndex:section] count];
return count;
Now when deleting I generate this same type of array like this:
NSMutableArray *contentsOfSection = [[_sectionsArray objectAtIndex:[indexPath section]] mutableCopy];
[contentsOfSection removeObjectAtIndex:[indexPath row]];
As you can see I'm deleting the object from an array that is not linked to the tableView, so it just returns an NSInternalInconsistencyException
Can anybody help me with this?
UPDATE:
[contentsOfSection removeObjectAtIndex:[pathToCell row]];
if ([contentsOfSection count] != 0) {
// THIS DOESN'T
[self.tableView deleteRowsAtIndexPaths:@[pathToCell] withRowAnimation:UITableViewRowAnimationFade];
}
else {
// THIS WORKS!
[_sectionsArray removeObjectAtIndex:[pathToCell section]];
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:[pathToCell section]] withRowAnimation:UITableViewRowAnimationFade];
}