当我滑动删除时,表格单元格崩溃。获取错误的访问错误

时间:2013-03-13 16:36:31

标签: ios objective-c crash tableview

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

在我的视图控制器中我有这段代码:

-(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];
    }

}

teacherplittablecontroller代码在这里:

- (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];


}

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

1 个答案:

答案 0 :(得分:2)

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

在我看来,这是一个很好的无限循环。

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