开发者

iPhone + sqlite3 + fmdb, What code do i need to put data into a UiTableView datasource?

If I was adding data from an array to the UITableView datasource array I'd use this, in viewDidLoad.

NSMutableArray *array = [[NSArray alloc] initWithObjects:@"Head First Design Patterns", @"Head First HTML & CSS", @"Head First iPhone", nil];
self.transactionsArray = array;开发者_JAVA技巧
[array release];

And this in cellForRowAtIndexPath

NSInteger row = [indexPath row];
cell.textLabel.text = [transactionsArray objectAtIndex:row];

But I want to link up the results from a select query, I'm using fmdb to access my database. Heres how I output data to the console with fmdb at the moment.

FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/mydb.db"];
if (![db open]) {
    NSLog(@"Could not open db.");
}

FMResultSet *rs = [db executeQuery:@"select * from myTable",  nil];
while ([rs next]) {
    NSLog(@"%@, %@, %@, %@, %@", [rs stringForColumn:@"pid"],
            [rs stringForColumn:@"desc"], 
            [rs stringForColumn:@"due"],
            [rs stringForColumn:@"price"],
            [rs stringForColumn:@"accumulated_price"]);
}
[rs close]; 
[db close];

How do i do this ?


Build a transaction array in the while loop like this:

[transactionArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:[rs stringForColumn@"pid", @"dictionaryLabel",........, nil];

EDIT: Yup thats right, to accesses it just use:

descLabelInTableView = [[arrayTmp objectAtIndex:indexPath.row] objectForKey:@"desc"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜