我正在使用数据库来填充表格视图。
我在NSMutable Array
中创建了AppDelegate
个对象。数组从DB填充如下:
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
const char *sql = "select barcode, vintage, vineyard, varietal from wine";
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
while(sqlite3_step(statement) == SQLITE_ROW) {
NSString *barcode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
DBHelper *wineObj = [[DBHelper alloc] initWithBarcode:barcode];
wineObj.vintage = sqlite3_column_int(statement, 1);
wineObj.vineyard = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
wineObj.varietal = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
[appDelegate.wineList addObject:wineObj];
[wineObj release];
}
}
}
所有数据都正确地进入数组,条形码的类型为NSString *
。但是,当显示表格视图时,条形码变为“Variable Not a CFString
”。当我选择一个项目时,我正在使用:
//get the bottle details for selected object
DBHelper *tempObj = [appDelegate.wineList objectAtIndex:indexPath.row];
DBHelper getBottleDetails:[appDelegate getDBPath]:tempObj.barcode];
由于条形码不再被解释为NSString
,因此应用程序崩溃。如何确保条形码保持有效?