2010-12-09 5 views
0

in app habe ich benutzerdefinierte tableview(UITableView *tableView) die Unterklasse von Uiviewcontroller & in Tableview Bearbeitung zeigen perfekt ist, aber wenn ich Zeile löschentableview Bearbeitung Crash-Anwendung in iPhone?

- (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 diesem Verfahren, wenn Unterbrechungspunkt geht an dieser Linie

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

mein Absturz was ich tue, um daraus zu kommen.

- (void) Prüfung: (NSIndexPath *) Wegs {

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] Delegat]; self.party = [PartyParser ladenParty]; if (_party! = Nil) { für (Player * player in _party.players) { NSLog (@ "% @,% @", player.name, player.alert); NSComparisonResult resultName, resultEmail, resultPhone, resultLocation; // NSString * str = [appDelegate.plistDict valueForKey: @ "flag"]; // if ([player.email länge]! = 0 & & player.alert == @ "1") { resultName = [dok.name vergleichen: spieler.name]; resultEmail = [doc.email vergleichen: player.email]; resultPhone = [doc.phone vergleichen: player.phone]; resultLocation = [doc.location compare: player.location]; if (resultName == 0 & & resultEmail == 0 & & resultPhone == 0 & & resultLocation == 0) { //lblName1.text = @ "gleich"; Player * playerr = [[Spielerzuweisung] init]; Spieler = Spieler; [_party.players removeObject: player]; //[_party.players removeObjectAtIndex: path.row]; Pause; } //} //if([player.email Länge] == 0 & & player.alert == @ "2") { else { resultName = [doc.name vergleichen: player.name]; resultPhone = [doc.phone vergleichen: player.phone]; if (resultName == 0 & & resultPhone == 0) { Spieler * playerr = [[Player alloc] init]; Spieler = Spieler; [_party.players removeObject: player]; Pause;
} } }

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

}

I GData xml in app bin mit der & Schreibleseoperationen unterstützen.

+0

was ist das Crash-Log auf der Konsole? – Swastik

+0

*** Beenden der App aufgrund der nicht abgefangenen Ausnahme 'NSInternalInconsistencyException', Grund: 'Ungültige Aktualisierung: ungültige Anzahl der Zeilen in Abschnitt 0. Die Anzahl der in einem vorhandenen Abschnitt enthaltenen Zeilen nach der Aktualisierung (1) muss der Anzahl von entsprechen Zeilen, die in diesem Abschnitt vor der Aktualisierung enthalten sind (1), plus oder minus der Anzahl der Zeilen, die in diesem Abschnitt eingefügt oder gelöscht wurden (0 eingefügt, 1 gelöscht). " 2010-12-09 14: 04: 01.478 ReferMe [29684: 207] Stack: –

Antwort

0

deleteRowsAtIndexPaths: Methode führt nur visuellen Effekt des Löschens, müssen Sie auch manuell entsprechendes Element aus der Datenquelle löschen, so Anzahl der Elemente darin Übereinstimmen wird mit dem, was von Ihrem Betrieb erwartet wird, zB:

//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 
+0

Ich bearbeite meine Frage Ich lösche Zeilendaten in XML aber es erzeugt denselben Absturz –

+0

Bitte formatieren Sie Ihren Code - es ist absolut unlesbar – Vladimir

+0

Hallo, iOS_User u habe irgendeine Lösung. Jetzt habe ich dasselbe Problem von den letzten 2 Tagen. Ich kann das nicht lösen. Kannst du mir bitte helfen? –