【问题标题】:tableview editing crash application in iphone?iphone中的tableview编辑崩溃应用程序?
【发布时间】: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


【解决方案1】:

deleteRowsAtIndexPaths: 方法仅执行删除的视觉效果,您还必须手动从数据源中删除相应的项目,以便其中的项目数量与您的操作预期一致,例如:

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

【讨论】:

  • 我编辑了我的问题,我删除了 xml 中的行数据,但它产生了同样的崩溃
  • 嗨,iOS_User 你有任何解决方案。现在我从过去 2 天开始面临同样的问题。我解决不了这个。你能帮帮我吗?
猜你喜欢
  • 2011-07-01
  • 1970-01-01
  • 2011-06-20
  • 2011-06-16
  • 1970-01-01
  • 1970-01-01
  • 2012-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多