Ios SQLite多个查询一个UITableview?
所以现在我已经用Ios SQLite多个查询一个UITableview?,ios,objective-c,sqlite,uitableview,Ios,Objective C,Sqlite,Uitableview,所以现在我已经用SQLite数据库中的数据填充了UITableview,我是通过填充NSMutableArray来完成的,然后填充UITableview。现在我只使用一个查询从数据库中获取数据,但我希望能够根据用户按下的单元格更改该查询。以下是阵列的外观: -(NSMutableArray *) authorList{ _theauthors = [[NSMutableArray alloc] initWithCapacity:10]; @try { NSFileMan
SQLite
数据库中的数据填充了UITableview
,我是通过填充NSMutableArray
来完成的,然后填充UITableview
。现在我只使用一个查询从数据库中获取数据,但我希望能够根据用户按下的单元格更改该查询。以下是阵列的外观:
-(NSMutableArray *) authorList{
_theauthors = [[NSMutableArray alloc] initWithCapacity:10];
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"StayhealthyExercises.sqlite"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured: %s", sqlite3_errmsg(db));
}
const char *sql = "SELECT * FROM strengthexercises WHERE primarymuscle LIKE '%abdominal%'";
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}else{
while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
sqlColumns * author = [[sqlColumns alloc] init];
author.Name = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
author.Muscle = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,2)];
author.Description = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 3)];
author.File= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 4)];
author.Sets= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 5)];
author.Reps= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 6)];
author.Equipment= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 7)];
author.PrimaryMuscle= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 8)];
author.SecondaryMuscle= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 9)];
author.Difficulty= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 10)];
[_theauthors addObject:author];
}
}
sqlite3_finalize(sqlStatement);
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}
@finally {
sqlite3_close(db);
return _theauthors;
}
}
如您所见,这是我的查询:
const char *sql = "SELECT * FROM strengthexercises WHERE primarymuscle LIKE '%abdominal%'";
我希望根据用户按下的单元格来更改此设置
任何帮助都将不胜感激
提前感谢。1.用户按下单元格时保存查询类型。2.根据保存的查询类型更改查询条件。这是一个很好的学习方法,但在生产环境中,您不能运行这样的代码,我认为您应该使用更好的方法来处理数据库,如果您打算使用SQLite作为数据库,那么这里有一个极好的库可以为您工作@johnMa您能举个例子吗?@Retro为什么这是一个糟糕的做法?