选择行时,检索下一个视图上的数据的详细信息

时间:2013-08-08 07:53:47

标签: iphone ios objective-c uitableview sqlite

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

将数据库创建为:

 -(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开发的新手,所以请按照我的说明建议如何在我的详细视图上显示数据。感谢

1 个答案:

答案 0 :(得分: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);
            }
        }

    }


}