0

当我滑动删除时,我的表格视图上不断出现此错误,通用编辑按钮将其置于编辑模式,我可以用它很好地删除它,但如果我滑动一个单元格,它会崩溃并返回错误的访问错误。我假设某处存在一些数据对话错误,但我不明白。我可以使用编辑并点击单元格将其删除,但滑动会使它崩溃。我有这个创建表视图的视图控制器。继承人的代码:

在我的视图控制器中,我有以下代码:

-(void)viewWillAppear:(BOOL)animated
{
    [self controllerSetup];

}

-(void)controllerSetup
{


        firstController = [[TeacherSplitTableController alloc] initWithStyle:UITableViewStyleGrouped];
        [firstTable setDataSource:firstController];
        [firstTable setDelegate:firstController];
        firstController.view = firstController.tableView;
        [firstController setDelegate:self];
        [self tableSetUp];

}

-(IBAction)edit:(id)sender
{
    if (!editting) {
            editting = YES;
            self.navigationItem.hidesBackButton = YES;
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(Add:)];
        //Displays add button over the back button
            [self.firstTable setEditing:YES animated:YES];
    } else {
            editting = NO;
            self.navigationItem.hidesBackButton = NO;
        self.navigationItem.leftBarButtonItem = NO;
            [self.firstTable setEditing:NO animated:YES];
    }

}

Teachersplittablecontroller 代码在这里:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source

        [self openDB];
        NSString *sql = [NSString stringWithFormat:@"DELETE FROM Children WHERE Name = '%@' ",[listofnames objectAtIndex:indexPath.row]]; //Queries table for the childs name and returns more data.
        sqlite3_stmt *statement;
        if (sqlite3_prepare_v2(Childdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK){
                    while (sqlite3_step(statement)==SQLITE_ROW) {
                    }
        }


        [listofnames removeObjectAtIndex:indexPath.row];
        [listoftickets removeObjectAtIndex:indexPath.row];
        //[theDataObject.names removeObjectAtIndex:indexPath.row];
        //[theDataObject.totaltickets removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    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
    }   
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self setEditing:editing animated:YES];


}

试图使代码保持苗条并与问题相关。如果您需要更多代码,请询问。但我看不到问题:(感谢所有帮助:)

4

1 回答 1

2
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self setEditing:editing animated:YES];
}

在我看来,这是一个不错的无限循环。

在应用程序崩溃之前是否有一些计算时间?如果没有 - 你是否启用了僵尸?

于 2013-03-13T16:40:53.733 回答