gpt4 book ai didi

iphone - 从多个表中过滤数据

转载 作者:行者123 更新时间:2023-11-29 04:44:02 25 4
gpt4 key购买 nike

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

任何人都可以建议我开始编写代码或为我提供任何示例吗?

最佳答案

对于具有两个组件的 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];
}

关于iphone - 从多个表中过滤数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9919651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com