【问题标题】:Table view sqlite data not deleting - iOS - iPad application表视图 sqlite 数据未删除 - iOS - iPad 应用程序
【发布时间】:2011-10-27 21:18:09
【问题描述】:

由于某种原因,我在数据库中的数据没有被删除,如果您能指出错误,我将不胜感激。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
NSUInteger row = [indexPath row];

    //Delete
    sqlite3_stmt *stmt2; 
    NSArray *del = [[arr objectAtIndex:row] componentsSeparatedByString:@" "];
    NSString *update1 = [NSString stringWithFormat:@"delete from survey where name='%@' and surname='%@';",[del objectAtIndex:1],[del objectAtIndex:2]];
    int x = sqlite3_prepare_v2(database, [update1 UTF8String], -1, &stmt2, nil);
    NSLog(@"x=%d",x);
    if (sqlite3_step(stmt2) != SQLITE_DONE)
        NSLog(@"Deletion Error.");

    [arr removeObjectAtIndex:row]; 
    [tblView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

非常感谢。

【问题讨论】:

    标签: objective-c ipad ios4 sqlite


    【解决方案1】:

    是数据库中的数据没有删除还是tableview中的数据没有删除。请通过检查您的数据库来确认(从命令行或 sqlite 管理器)。

    您的代码中可能出现的错误出现了。 1)不要将 NSString 传递给 sqlite3,像这样传递它const char *query = [queryStr UTF8String]; 2) 确保您正在完成/提交 sqlite 语句。

    sqlite3_finalize(stmt)
    

    同时关闭 sqlite 数据库。

    【讨论】:

    • 你好,是数据库中的数据没有被删除,它只在表视图上删除。谢谢。
    • 你能告诉我正在打印的 x 的值吗?而且也没有必要通过;连同查询
    • 太棒了!我删除了“;”它奏效了!!非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多