我在xcode 4.6中有一个问题。
MainStoryboard包含一个按钮& TableView。显然,当我运行应用程序并单击Button时,Table视图只显示数据的第一列和最后一列。
我使用的是sqlite3,在这里我创建了一个数据库和表,该数据库和表目前有一行由14列组成的数据。第一列是您信息的主键。
下面是我的UITableViewCell代码*动作按钮。
任何洞察力都将不胜感激。
谢谢。
-(UITableViewCell *) tableView :(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {静态NSString *单元标识符= @"Cell";UITableViewCell *cell =tableView cellForRowAtIndexPath
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;
}
发布于 2013-06-10 21:54:39
因为您一遍又一遍地分配给同一个位置(cell.detailTextLabel.text
),所以只有最后一个才算在内。这就是为什么你只看到最后一篇专栏。
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",aDefenseStats.defense_sack_mp];
我想你真正想要的是每一列都有一个单元格。您可以通过以下方法获得这个结果:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 14;
}
然后更新您的tableView:cellForRowAtIndexPath:
方法以选择适当的列值,可能使用一个14大小写的switch
语句,并将该值分配给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;
另外,不要将任何东西分配给cell.detailTextLabel.text
。
https://stackoverflow.com/questions/17033395
复制相似问题