-4

我的下一个视图有四个字段,我想在表格上选择名称时显示所有详细信息。

创建数据库的代码如下:

 -(IBAction) saveData
    {
        sqlite3_stmt    *statement;
        const char *dbpath = [databasePath UTF8String];
        if (sqlite3_open(dbpath, &Information) == SQLITE_OK)
        {
            NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO CONTACTS (name,address, phone,imageUrl) VALUES (\"%@\", \"%@\", \"%@\",\"%@\")", name.text,address.text,phone.text,imageUrl.text];
                const char *insert_stmt = [insertSQL UTF8String];
                sqlite3_prepare_v2(Information, insert_stmt, -1, &statement, NULL);

                if (sqlite3_step(statement) == SQLITE_DONE)
                {
                    status.text = @"Contact added";

                    name.text = @"";            

                    address.text = @"";

                    phone.text = @"";  i
                    imageUrl.text=@"";

                } else 


                {
                    status.text = @"Failed to add contact";
                }
                sqlite3_finalize(statement);


                sqlite3_close(Information);
        }
    }

我是 ios 开发的新手,所以请建议如何在我的详细视图中显示数据,如上所述。谢谢

4

1 回答 1

0

对于显示数据你可以试试这个

-(void)displayData
{
    const char *dbpath = [databasePath UTF8String];

    if(sqlite3_open(dbPath, &Information)==SQLITE_OK)
    {
        const char *qry=[@"select * from CONTACTS" UTF8String];
        sqlite3_stmt *statement;

        if (sqlite3_prepare_v2(dtdb, qry, -1, &statement, NULL)==SQLITE_OK)
        {
            while (sqlite3_step(statement)==SQLITE_ROW)
            {
                NSString *name=[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 0)];
                NSString *address=[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 1)];
                NSString *phone=[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 2)];
                NSString *imageUrl=[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 3)];

                NSLog(@"name:%@ , address :%@ , phone:%@ , imageurl:%@",name,address,phone,imageUrl);
            }
        }

    }


}
于 2013-08-08T08:10:10.777 回答