收到意外的“EXC_BAD_ACCESS”

时间:2011-05-26 14:03:43

标签: iphone xcode exc-bad-access

当我从表格视图中删除单元格时:发生以下错误:

Program received signal:  “EXC_BAD_ACCESS”.
warning: Unable to read symbols for /Xcode3.2.5/Platforms/iPhoneOS.platform/DeviceSupport/4.3.2 (8H7)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).

这里我从单元格中删除对象及其来自calander的事件:

if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        //Get the object to delete from the array.
        lovkid *mykids = (lovkid *)[appDelegate.actionarray1 objectAtIndex:indexPath.row];
        appDelegate.actionId = mykids.Id;

        //delete from calender
        if( [ mykids.Event isEqualToString:@"empty"])
        {
        }
        else
        {
            EKEvent* event2 = [appDelegate.eventStore eventWithIdentifier:mykids.Event];
            if (event2 != nil) 
            {  
                NSError* error = nil;
                [appDelegate.eventStore removeEvent:event2 span:EKSpanThisEvent error:&error];
            } 
        }

        //delete end
        [mykids deleteAction];
        [appDelegate.actionarray1 removeObjectAtIndex:indexPath.row];

        //Delete the object from the table.
        [localTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [localTable reloadData];
        a = 0;
    }
    else 
    {
        //NSLog(@"test");
    }

从db中删除:

deleteStmt1 = nil;
    if(deleteStmt1 == nil) 
    {
            const char *sql = "delete from actions where id = ?";
            if(sqlite3_prepare_v2(database1, sql, -1, &deleteStmt1, NULL) != SQLITE_OK)
                NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(database1));

    //When binding parameters, index starts from 1 and not zero.
        sqlite3_bind_int(deleteStmt1, 1,(int)appDelegate.actionId);

        if (SQLITE_DONE != sqlite3_step(deleteStmt1)) 
            NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database1));

        sqlite3_reset(deleteStmt1);
        sqlite3_finalize(deleteStmt1);
    }

出现此错误的原因是什么?

1 个答案:

答案 0 :(得分:1)

我建议删除该行:

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

如果您按reloadData重新加载表格,则无需删除该行。该表将重新加载,反映新的数据源状态。

另一方面,如果您可以更顺畅地刷新表格,则可以调查beginUpdatesendUpdates。在这种情况下,使用deleteRowsAtIndexPaths是有意义的。

我不知道这是否能解决您的崩溃问题。如果没有,我建议您在调试器下执行,这样您就可以确切地找出导致崩溃的违规语句。