Xcode - Goal C: Removing a Failure in a Row Table

Welcome! I just worked all night on this, but not a banana; perhaps you have an understanding!

I work with standard NSMutableArray:

self.itemTable = [[NSMutableArray alloc]
                 initWithObjects:@"House.",
                 @"Car.",
                 @"Keys.", nil];

Now when I click "EDIT" in the navigation bar and delete the line, I get the following error message

The application terminated due to the uncaught exception "NSInternalInconsistencyException", reason: "Invalid update: invalid number of lines in section 0. The number of lines contained in an existing section after updating (3) must be equal to the number of lines contained in this section before updating (3 ), plus or minus the number of inserted or deleted rows from this section (inserted 0, 1 deleted) and plus or minus the number of rows moved to or from this section (0 moved, 0 deleted).

I use this code for the delete command:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {


[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

Any info on how to make the delete line function work?

EDIT :

Found: placing the following line of code in the processed file:

[self.itemTable removeObjectAtIndex:indexPath.row];

What the removal code does:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {

[self.itemTable removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}
+3
source
3

. . - tableview . , / .

:

 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (editingStyle == UITableViewCellEditingStyleDelete)
     {
        //add code here for when you hit delete
        [self deleteItemAtRowIndex:indexPath];
    }
}


-(void)deleteItemAtRowIndex:(NSIndexPath *)indexpath
{
[pTableDataDataArray removeObjectAtIndex:indexpath.row];

[pTableView beginUpdates];
//[self LoadTempletesData];    no need to reload, simply remove row that to is to be delete
[pTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexpath] withRowAnimation:UITableViewRowAnimationNone];
//make changes
[pTableView endUpdates];
}

, .

+1

( , , ), , . - . ( , ). ,

[tableView beginUpdates];
//make changes
[tableView endUpdates];
0

Remember to update the data source each time you add or remove content from a table that is retrieved from the data source itself.

0
source

All Articles