UITableview每行两个数据
问题描述:
我想在我的tableview每行上有两个数据。 喜欢的东西最近调用(左边的名字,右边的一天)UITableview每行两个数据
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
//cell.selectionStyle = UITableViewCellStyleValue1 ;
}
// Configure the cell.
NSDictionary *dictionary = [listaOggetti objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"Elementi"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
NSArray *array1 = [dictionary objectForKey:@"Tipo"];
NSString *cellDetail = [array1 objectAtIndex:indexPath.row];
if ([indexPath row] == 0){
cell.textLabel.text = cellValue;
cell.textAlignment = UITextAlignmentCenter;
cell.backgroundColor = [UIColor blueColor];
cell.font = [UIFont systemFontOfSize:13];
} else {
cell.textLabel.text = cellDetail;
cell.detailTextLabel.text = cellValue;
}
return cell;
}
我已经尝试上使用不同的风格
initWithStyle
没有任何结果(只显示我的详细信息在右边)。 在NSLOG中,我看到了cellDetail的正确值。
{
Elementi = (
"Chiamate e Videochiamate Nazionali",
"08m:43s",
"1h:31m:17s",
"1h:40m:00s"
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
},
{
Elementi = (
"SMS e MMS Nazionali",
21,
29,
50
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
},
{
Elementi = (
"Traffico Dati FMM",
"69.95 MB",
"954.05 MB",
"1024.00 MB"
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
},
{
Elementi = (
Skype,
"00m:00s",
"3h:20m:00s",
"3h:20m:00s"
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
},
{
Elementi = (
"WWW3, Yahoo!, Google, eBay e altri servizi",
"0.00 MB",
"100.00 MB",
"100.00 MB"
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
}
)
我的目标是获得细胞是这样的:
答
我会考虑creating a custom Cell,它很容易做到,如果做得好,它看起来真的很棒。
否则,您的代码看起来不错,请检查您的标签是否已被分配(而不是零)。
请注意,您的数据集中有多少项?我只问,因为如果它只有1,你从来没有设置detailTextLabel。
答
我相信你需要初始化这样的细胞,要初始化细胞
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
在使用不正确的风格
答
谢谢大家,我的代码没问题,故障在第二个数组上。 解决了这种方式:
NSDictionary *dictionary1 = [listaDettaglioOggetti objectAtIndex:indexPath.section];
NSArray *array1 = [dictionary1 objectForKey:@"Tipo"];
NSString *cellDetail = [array1 objectAtIndex:indexPath.row];
最后一个问题:
我将修改每一节的第一行(修改字体大小,颜色,aligment)。 我已经觉得是这样的:
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
if (sectionRows == 0){
cell.textLabel.text = cellDetail;
cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
cell.detailTextLabel.backgroundColor = [UIColor blueColor];
cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
} else {
cell.textLabel.text = cellDetail;
cell.detailTextLabel.text = cellValue;
}
但不要让魔法:d 请让我知道,如果它是更好地打开另一个话题,或者我们可以继续在这里。
`dequeueReusableCellWithIdentifier`返回一个指向一个可重复使用的单元格或零,而他之后和allocs检查零如果合适 – 2010-12-06 14:55:20
@Luke Mcneice我相信初始化细胞 – 2010-12-06 15:01:26
OK,用于校正感谢时,他使用了错误的风格 – 2010-12-06 15:09:09