【发布时间】:2010-12-09 07:52:59
【问题描述】:
在应用程序中我有自定义 tableview(UITableView *tableView) uiviewcontroller 的子类和在 tableview 编辑中完美显示但是当我删除行时
- (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
}
}
当断点到达该行时在此方法中
[tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
我的应用程序崩溃了我所做的事情。
-(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:(播放器 *)doc{
//ReferMeAppDelegate *appDelegate = (ReferMeAppDelegate *) [[UIApplication sharedApplication]delegate];
self.party = [PartyParser loadParty];
如果(_party!= nil){
for (玩家 *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 比较:player.email];
resultPhone = [doc.phone 比较:player.phone];
resultLocation = [doc.location 比较:player.location];
if(resultName == 0 && resultEmail == 0 && resultPhone == 0 && resultLocation == 0){
//lblName1.text = @"equal";
玩家 *playerr = [[玩家分配]init];
玩家 = 玩家;
[_party.players removeObject:playerr];
//[_party.players removeObjectAtIndex:path.row];
休息;
}
// }
//if([player.email 长度] == 0 && player.alert == @"2"){
别的{
resultName = [doc.name compare:player.name];
resultPhone = [doc.phone 比较:player.phone];
if (resultName == 0 && resultPhone == 0) {
玩家 *playerr = [[玩家分配]init];
玩家 = 玩家;
[_party.players removeObject:playerr];
休息;
}
}
}
for (Player *player in _party.players) {
NSLog(@"after match case player names");
NSLog(@"%@", player.name);
}
[PartyParser saveParty:_party];
}
}
我在支持读写操作的应用程序中使用 GData xml。
【问题讨论】:
-
控制台的崩溃日志是什么?
-
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:第 0 节中的行数无效。更新后现有节中包含的行数 (1)必须等于更新前该节中包含的行数 (1),加上或减去从该节插入或删除的行数(0 插入,1 删除)。 2010-12-09 14:04:01.478 参考我[29684:207] 堆栈:
标签: iphone objective-c uitableview row editing