好吧,出於某種原因,我得到一個愚蠢的錯誤。將值附加到我的NSMutableArray
-(void) getAllRowsFromTableNamed: (NSString *) tableName {
NSString *qsql = @"SELECT supplier from products";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(db, [qsql UTF8String], -1, &statement, nil) ==
SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
char *field1 = (char *) sqlite3_column_text(statement,0);
NSMutableString *field1Str = [[NSMutableString alloc] initWithUTF8String: field1];
listofsuppliers = [NSMutableArray arrayWithObjects:field1Str, nil];
NSLog(@"list of suppliers %@",listofsuppliers);
[field1Str release];
}
sqlite3_finalize(statement);
}
}
在我的記錄,我發現了以下內容:
QueensWayInventory[13192:f803] list of suppliers ("(null)")
QueensWayInventory[13192:f803] list of suppliers ("(null)")
QueensWayInventory[13192:f803] list of suppliers (Dell)
QueensWayInventory[13192:f803] list of suppliers (Apple)
QueensWayInventory[13192:f803] list of suppliers (Apple)
QueensWayInventory[13192:f803] list of suppliers (Dell)
我想這個代替:
QueensWayInventory[13192:f803] list of suppliers (
Dell,
Apple
)
它必須是很簡單的東西,我做錯了。當我創建一個靜態列表時,我知道它是如何實現的,但是當我試圖從數據庫創建一個動態讀取時,卻沒有。
好的非常感謝,我得到了它使用nsmutablearray。問題如你所示。我絕對不得不把它放在循環之外,它工作。非常感謝(Y) – user984373