0

SQLite を使用して Xcode でデータベースを開発するのは初めてで、テーブルからデータを取得して Tableview に入れるアプリを構築しようとしています。

Tableview に次のコードがあります。

-(UITableViewCell *) tableView : (UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
jobs =[[NSMutableArray alloc] init];
id cellvalue;

NSString *querySQL = [NSString stringWithFormat: @"select jobTitle FROM job"];
sqlite3_stmt *statement;
const char *query_stmt = [querySQL UTF8String];
static NSString *identifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:identifier];


if (cell == nil)
{
    cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
    while (sqlite3_step(statement) == SQLITE_ROW)
    {
        //[jobs addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
        [jobs addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 0)]];
        cellvalue =[jobs objectAtIndex:indexPath.row];
        cell.textLabel.text = cellvalue;
       // cell.textLabel.text = [jobs objectAtIndex:[indexPath row]]; -- Tried this but does not work.

    }
}
return cell;
}

ここで、JobTitle は SQLITE DB のテキスト フィールドです。テーブル名はジョブです。次の手順で SIGBART エラーが発生します。

cellvalue =[jobs objectAtIndex:indexPath.row];
cell.textLabel.text = cellvalue;

または私は次のことを試みました

cell.textLabel.text = [jobs objectAtIndex:[indexPath row]]; 

私が試したとき:

cell.textlabel.text = @"Test"

それはうまくいきます。

私はここで立ち往生しており、データベースからTableViewセルにテキスト値を割り当てる方法について助けていただければ幸いです。現在、テーブルには 2 行あります。

4

2 に答える 2