我想在iphone应用程序中显示数据库中的数据。我使用以下代码来执行它。但它没有在表格中显示数据。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &_beaconDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:
@"SELECT vendor_name, enter_message, enter_image FROM beacons WHERE major=%d AND minor=%d", major[indexPath.row], minor[indexPath.row]];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(_beaconDB,
query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *title = [[NSString alloc]
initWithUTF8String:
(const char *) sqlite3_column_text(
statement, 0)];
NSString *description = [[NSString alloc]
initWithUTF8String:(const char *)
sqlite3_column_text(statement, 1)];
cell.title.text = title;
cell.description.text = description;
}
sqlite3_finalize(statement);
}
sqlite3_close(_beaconDB);
}
return cell;
}
在上面的"专业"是一个数组。我想逐个获取数组值。
提前致谢。
答案 0 :(得分:1)
我解决了这个问题。我在下面的一行中犯了错误。
@"SELECT vendor_name, enter_message, enter_image FROM beacons WHERE major=%d AND minor=%d", major[indexPath.row], minor[indexPath.row]];
而不是使用major[indexPath.row]
我必须使用major[objectAtIndex: indexPath.row]
以及minor