Error 'Invalid update: invalid number of rows in section 0' attempting to delete row in table

前端 未结 2 1486
忘了有多久
忘了有多久 2020-12-31 03:54

My code appears to run just fine but when I swipe to delete a line within my UITableView, the app crashes with the following:

Error

LittleTo

2条回答
  •  青春惊慌失措
    2020-12-31 04:26

    I figured it out with the help from above and some thinking.

    First, I finished the actual deleteToDoItem code

    - (ToDoItem *) deleteToDoItem: (ToDoItem *) todoitem {
    
        [ToDoItems removeObject:todoitem];
    
        return todoitem;
    }
    

    Then the code above

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
        ToDoItem *toDoItem = [[ToDoItemSvc retrieveAllToDoItems] objectAtIndex:indexPath.row];
    
        [ToDoItemSvc deleteToDoItem:toDoItem];
        [self.tableView reloadData];
    
        NSLog(@"Removing data");
    }
    

    This runs and allows me to delete my item like I want!!

提交回复
热议问题