0
votes

in app i have custom tableview(UITableView *tableView) which subclass of uiviewcontroller & in tableview editing is show perfectly but when i delete row

- (void)tableView:(UITableView *)tableView1 commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        //[appDelegate deleteItemAtIndexPath:indexPath];
        [self testing:indexPath];
        [tableView deleteRowsAtIndexPaths:
         [NSArray arrayWithObject:indexPath] 
                     withRowAnimation:UITableViewRowAnimationFade];//in this line app crash 
        NSLog(@"delete row");
        [tableView reloadData];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        //nothing to do item already added
    }   
} 

in this method when breakpoint goes at that line

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

my application crash what i do for come out from it.

-(void)testing:(NSIndexPath *)path{

Player *doc = [[Player alloc]init];
NSMutableArray* reversedArray = [[NSMutableArray alloc] initWithArray:[[[[NSArray alloc] initWithArray: _data] reverseObjectEnumerator] allObjects]];

doc = [reversedArray objectAtIndex:path.row];
NSLog(@"%@,%d", doc.name,path.row);
[self deleteRow:doc];

}

-(void)deleteRow:(Player *)doc{

// ReferMeAppDelegate *appDelegate = (ReferMeAppDelegate *) [[UIApplication sharedApplication]delegate]; self.party = [PartyParser loadParty]; if (_party != nil) { for (Player *player in _party.players) { NSLog(@"%@, %@", player.name,player.alert); NSComparisonResult resultName, resultEmail, resultPhone, resultLocation; //NSString *str = [appDelegate.plistDict valueForKey:@"flag"]; //if ([player.email length] != 0 && player.alert == @"1"){ resultName = [doc.name compare:player.name]; resultEmail = [doc.email compare:player.email]; resultPhone = [doc.phone compare:player.phone]; resultLocation = [doc.location compare:player.location]; if(resultName == 0 && resultEmail == 0 && resultPhone == 0 && resultLocation == 0){ //lblName1.text = @"equal"; Player *playerr = [[Player alloc]init]; playerr = player; [_party.players removeObject:playerr]; //[_party.players removeObjectAtIndex:path.row]; break; } // } //if([player.email length] == 0 && player.alert == @"2"){ else{ resultName = [doc.name compare:player.name]; resultPhone = [doc.phone compare:player.phone]; if (resultName == 0 && resultPhone == 0) { Player *playerr = [[Player alloc]init]; playerr = player; [_party.players removeObject:playerr]; break;
} } }

        for (Player *player in _party.players) {
            NSLog(@"after match case player names");
            NSLog(@"%@", player.name);
        }
        [PartyParser saveParty:_party];
    }

}

I'm using GData xml in app which support read & write operations.

1
what is the crash log on console? - Swastik
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).' 2010-12-09 14:04:01.478 ReferMe[29684:207] Stack: - iOS_User

1 Answers

0
votes

deleteRowsAtIndexPaths: method only performs visual effect of deletion, you must also manually delete corresponding item from your data source so number of items in it will be consistent with what is expected from your operation, e.g.:

//You need to remove item from data source
[yourMutableDataArray removeObjectAtIndex:indexPath.row]; 
// Tell table view to remove the corresponding item cell
[tableView deleteRowsAtIndexPaths:
             [NSArray arrayWithObject:indexPath] 
             withRowAnimation:UITableViewRowAnimationFade];//in this line app crash 
NSLog(@"delete row");
//[tableView reloadData]; // You do not need this line