At first my table view is empty, and then you can add your own cells to it. When you delete those cells, everything works fine. However, if you delete the last cell, then my NSMutableArray has no objects in it, and I get this error in my console (also, I’m using Core Data to save the cells):
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFBatchFaultingArray objectAtIndex:]: index (123150308) beyond bounds (1)'
I also tried putting in this line of code, but I still get the same results:
//arr is my mutable array
if ([arr count] == 0) {
NSLog(@"No Cells");
}
This is how I delete an object from the table view:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[arr removeObjectAtIndex:0];
[context deleteObject:[arr objectAtIndex:0]];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
How would I solve this problem?
Ok.
There are two problems I have found in you code.
1- Why you are removing every time object at Index 0 ?
2- After removing an object from array
[arr removeObjectAtIndex:0];than from the same array of index you are passing an object to core Data to delete itThis might be the problem.
This will surely help you.
Use this:
Thanks 🙂