IOS数据库未检索数据

IOS数据库未检索数据,ios,xcode,sqlite,Ios,Xcode,Sqlite,我想在iphone应用程序的数据库中显示表中的数据。我使用下面的代码来执行它。但它没有在表格中显示数据 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomCell"];

我想在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;
}
在上面的“major”是一个数组。我想一个接一个地得到数组值


提前谢谢。

我解决了这个问题。我在以下几行中犯了错误

@"SELECT vendor_name, enter_message, enter_image FROM beacons WHERE major=%d AND minor=%d", major[indexPath.row], minor[indexPath.row]];
而不是使用
mair[indexPath.row]


我必须使用
major[objectAtIndex:indexath.row]
以及
minor

函数
numberOfRowsInsection
返回多少行?同样,您不认为将此数据检索代码放在
cellforrowatinexpath
函数之外是正确的。它返回的值的数量以主键表示。以及如何将此检索代码置于cellForRowAtIndexPath之外,并在TableCells中显示值。参见本教程,它非常古老,但非常有用。此代码不处理错误。至少要记录下这个过程。