SQLite多个查询一个UITableview?

时间:2013-12-21 05:50:25

标签: ios objective-c sqlite uitableview

所以现在我已经使用来自UITableview数据库的数据填充了我的SQLite,我如何填充NSMutableArray然后填充我的UITableview。现在,我只使用一个Query来从数据库中获取数据,但我希望能够根据用户按下的单元格来更改该查询。这是数组的样子:

-(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%'";

我希望根据用户按下的单元格进行更改?

非常感谢任何帮助。

提前致谢。

0 个答案:

没有答案