0

xcode 4.6 で問題が発生しています。

MainStoryboard には、Button と TableView が含まれています。どうやら、アプリを実行してボタンをクリックすると、テーブルビューにはデータの最初の列と最後の列のみが表示されます。

現在、14列で構成される1行のデータを持つデータベースとテーブルを作成したsqlite3を使用しています。最初の列は、情報の主キーです。

以下は私のUITableViewCellコード*アクションボタンです。

どんな洞察も大歓迎です。

ありがとう。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (!cell) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

DefenseStats *aDefenseStats = [arrayOfDefenseStats objectAtIndex:indexPath.row];

cell.textLabel.text = aDefenseStats.defense_team_name_mp;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_games_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2f",aDefenseStats.defense_points_per_game_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2f",aDefenseStats.defense_yards_per_game_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2f",aDefenseStats.defense_rushing_yards_per_game_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2f",aDefenseStats.defense_passing_yards_per_game_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_interception_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_interception_touchdown_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_forced_fumble_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_defensive_touchdown_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_tackle_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_pass_deflection_mp];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_sack_mp];

return cell;

}

  • (IBAction)displayDefenseStatsButton:(id)送信者 {

    sqlite3_stmt *ステートメント;

    if (sqlite3_open([dbPathString UTF8String], &americanfootballDB)==SQLITE_OK) { [arrayOfDefenseStats removeAllObjects];

    NSString *querySql = [NSString stringWithFormat:@"SELECT * FROM DEFENSE_TEAM_STATS"];
    const char* query_sql = [querySql UTF8String];
    
    if (sqlite3_prepare(americanfootballDB, query_sql, -1, &statement, NULL) == SQLITE_OK)
    {
        while (sqlite3_step(statement)==SQLITE_ROW)
        {
    
            NSString *defense_team_name_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 1)];
            NSString *defense_games_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 2)];
            NSString *defense_points_per_game_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 3)];
            NSString *defense_yards_per_game_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 4)];
            NSString *defense_rushing_yards_per_game_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 5)];
            NSString *defense_passing_yards_per_game_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 6)];
            NSString *defense_interception_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 7)];
            NSString *defense_interception_touchdown_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 8)];
            NSString *defense_forced_fumble_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 9)];
            NSString *defense_defensive_touchdown_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 10)];
            NSString *defense_tackle_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 11)];
            NSString *defense_pass_deflection_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 12)];
            NSString *defense_sack_string = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 13)];
    
            DefenseStats *defensestats =[[DefenseStats alloc]init];
    
            [defensestats setDefense_team_name_mp:defense_team_name_string];
            [defensestats setDefense_games_mp:[defense_games_string intValue]];
            [defensestats setDefense_points_per_game_mp:[defense_points_per_game_string floatValue]];
            [defensestats setDefense_yards_per_game_mp:[defense_yards_per_game_string floatValue]];
            [defensestats setDefense_rushing_yards_per_game_mp:[defense_rushing_yards_per_game_string floatValue]];
            [defensestats setDefense_passing_yards_per_game_mp:[defense_passing_yards_per_game_string floatValue]];
            [defensestats setDefense_interception_mp:[defense_interception_string intValue]];
            [defensestats setDefense_interception_touchdown_mp:[defense_interception_touchdown_string intValue]];
            [defensestats setDefense_forced_fumble_mp:[defense_forced_fumble_string intValue]];
            [defensestats setDefense_defensive_touchdown_mp:[defense_defensive_touchdown_string intValue]];
            [defensestats setDefense_tackle_mp:[defense_tackle_string intValue]];
            [defensestats setDefense_pass_deflection_mp:[defense_pass_deflection_string intValue]];
            [defensestats setDefense_sack_mp:[defense_sack_string intValue]];
    
            [arrayOfDefenseStats addObject:defensestats];
        }
    }
    

    [[self myTableView]reloadData]; } */

4

1 に答える 1

0

Since you're assigning to the same location (cell.detailTextLabel.text) over and over and over again, only the last one will count. That's why you only see the last column.

cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_sack_mp];

I think what you really want is a cell for each column. You'll get that with the following:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return 14;
}

Then update your tableView:cellForRowAtIndexPath: method to select the appropriate column value, probably with a 14-case switch statement and assign the value to cell.textLabel.text:

NSString *defenseStatValue;
switch (indexPath.row)
{
  case (0):
    defenseStatValue = aDefenseStats.defense_team_name_mp;
    break;
  case (1):
    defenseStatValue = [NSString stringWithFormat:@"%d",aDefenseStats.defense_games_mp];
    break;
  /* Add a case for each column index possible. */
}
cell.textLabel.text = defenseStatValue;

Also, don't assign anything to cell.detailTextLabel.text.

于 2013-06-10T21:54:39.440 に答える