过滤来自多个表的数据

时间:2012-03-29 05:38:25

标签: iphone objective-c ios ipad uitableview

我正在做一个iPad应用程序。我的UIView将如下。将有2个UITabelview, UITabelview和UIButton表连接到SQLite。艰巨的任务是我想在每个表中选择一行,并使用UIButton(这是一个搜索按钮)在UITextview中提供相关数据。

任何人都可以建议我启动代码或提供任何示例。

1 个答案:

答案 0 :(得分:1)

对于带有两个组件的UIPickerView的

,请参阅以下链接http://www.iphonetut.com/iphone_apps_-_interface_builder/86/uipickerview_with_two_component_example

这是您的查询的完美答案,您只需在按钮按下事件中添加SQL功能

-(IBAction)buttonPressed
{
    NSString *msg = [NSString stringWithFormat: @"I am feeling %@ for the activity %@",
                    [names objectAtIndex:[pickerView selectedRowInComponent:0]],
                    [age objectAtIndex:[pickerView selectedRowInComponent:1]]];

    NSLog(@"%@,%@",[nameArray objectAtIndex:[pickerView selectedRowInComponent:0]],[ageArray objectAtIndex:[pickerView selectedRowInComponent:1]]);

    sqlite3 *database;
    NSMutableArray *Favorite=[[NSMutableArray alloc] init];
    if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { 
        NSLog(@"Open");
        NSString *sql=[NSString stringWithFormat:@"SELECT * FROM thirdTable WHERE name='%@' AND age='%@'", [nameArray objectAtIndex:[pickerView selectedRowInComponent:0]], [ageArray objectAtIndex:[pickerView selectedRowInComponent:1]]];
        NSLog(@"sqlTm p %@", sqlTmp);
        const char *sqlStmt=[sqlTmp UTF8String]; 
        sqlite3_stmt *cmp_sqlStmt; 
        if(sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL) == SQLITE_OK) {
             NSLog(@"prepare stmt ");
             while(sqlite3_step(cmp_sqlStmt)==SQLITE_ROW) { 

             NSString *a1=[NSString stringWithUTF8String:(char *)sqlite3_column_text(cmp_sqlStmt, 0)];
             NSMutableDictionary *Question=[NSDictionary dictionaryWithObjectsAndKeys:
                                           a1,@"detail",nil];
             [Favorite addObject:Question];
        }
    }
    sqlite3_finalize(cmp_sqlStmt);

sqlite3_close(database);

    if(Favourite.count >0){
      textView.text = [NSString stringWithFormat:@"%@", [Favorite objectAtImadex:0]];
    }
[Favorite release];
}