簡體   English   中英

iPhone + sqlite3 + fmdb,我需要什么代碼將數據放入UiTableView數據源?

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

如果我要將數據從數組添加到UITableView數據源數組,則可以在viewDidLoad中使用它。

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

而這在cellForRowAtIndexPath中

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

但是我想鏈接選擇查詢的結果,我正在使用fmdb訪問我的數據庫。 這是我現在如何使用fmdb將數據輸出到控制台的方法。

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];

我該怎么做呢 ?

在while循環中構建一個事務數組,如下所示:

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

編輯:是的,要訪問它,只需使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM