2

我正在使用数据库来填充表视图。

NSMutable ArrayAppDelegate. 数组是从数据库中填充的,如下所示:

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,所以应用程序崩溃。如何确保条形码保持有效使用?

4

0 回答 0