【问题标题】:SQLite data insert not reflected in tableSQLite 数据插入未反映在表中
【发布时间】:2010-12-27 07:33:41
【问题描述】:

我可以插入我的数据,但我不能在我的表格视图中显示它们。我试过[tableview reloadData] 但没有成功

这是我的代码:

-(void)gButtonTapped:(id)sender
{  


    NSLog(@"right nav bar button is  hit%@ ",storePaths);
    //[self readAnimalsFromDatabase2];

    appDelegate = (DatabaseTestAppDelegate *)[[UIApplication sharedApplication] delegate];
    sqlite3 *database;

     sqlite3_stmt *compiled_statement1;
     if(sqlite3_open([storePaths UTF8String], &database) == SQLITE_OK) {
         //const char *sqlStatement = 


         NSString *newQuery = [NSString stringWithFormat:@"insert into cat_tbl (cat_id,names,imgs) values ('12','test1','r.png')"];

        // NSString *newQuery = [NSString stringWithFormat:@"select * from list_tbl"];

        const char *sql = [newQuery cStringUsingEncoding:NSASCIIStringEncoding];


        NSLog(@"update query is %@",newQuery);

        if(sqlite3_prepare_v2(database, sql, -1, &compiled_statement1, NULL) == SQLITE_OK)
        {
            int result = sqlite3_step(compiled_statement1);
            sqlite3_reset(compiled_statement1);
            NSLog(@"result %d", result);

            if(result != SQLITE_ERROR) {
                int lastInsertId =  sqlite3_last_insert_rowid(database);
                NSLog(@"x %d", lastInsertId);
        }




        }

    }

    sqlite3_finalize(compiled_statement1);


    sqlite3_close(database);
    [tableView reloadData];// this is also  not working 

}

【问题讨论】:

  • 请建议如何在表格视图上反映新数据:(

标签: sqlite uitableview iphone-sdk-3.0


【解决方案1】:

您需要通过调用选择查询来更新您的表格视图数据源,或者通过在新值成功插入数据库时​​添加新值来更新您的数据源。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 2019-07-10
    • 2012-05-17
    • 1970-01-01
    相关资源
    最近更新 更多