- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSString *show=[NSString stringWithFormat:@"%@",[res objectAtIndex:18]];
float f=[show floatValue];
show1=[NSString stringWithFormat:@"%.2f %%",f];
[show1 retain];
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if (indexPath.row % 2 == 0) {
// EVEN
cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"EvenCell"] autorelease];
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
UIColor *colour = [[UIColor alloc] initWithRed: (208.0/255.f) green: (231.0/255.f)
blue: (241.0/255.f) alpha: 1.0];
bg.backgroundColor = colour;
cell.backgroundView = bg;
cell.textLabel.backgroundColor = bg.backgroundColor;
[bg release];
cell.detailTextLabel.backgroundColor=[UIColor clearColor];
cell.detailTextLabel.text=show1;
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else {
// ODD
cell = [tableView dequeueReusableCellWithIdentifier:@"OddCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"OddCell"] autorelease];
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
UIColor *colour = [[UIColor alloc] initWithRed: (143.0/255.f) green: (169.0/255.f)
blue: (180.0/255.f) alpha: 1.0];
bg.backgroundColor = colour;
cell.backgroundView = bg;
cell.textLabel.backgroundColor = bg.backgroundColor;
[bg release];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
这是我的代码,你可以看到我重装在viewDidAppear秀王数据,我的数据,需要放在的tableView在detailLabel.text细胞。现在不要看我的奇怪单元部分因为它不可用的atm。我只有1个单元格和它的单元格。现在我的问题是当我删除[self.tableView reloadData];行它的工作良好不更新,但它显示细胞。当我把它我无法看到tableView中的单元格它的所有空任何想法为什么?我在哪里做错了?reloadData doen't绘制细胞的tableview
EDIT1:
cell.backgroundView = bg;
cell.textLabel.backgroundColor = bg.backgroundColor;
[bg release];
cell.detailTextLabel.backgroundColor=[UIColor clearColor];
}
cell.detailTextLabel.text=show1;
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
好我改变它,把它弄出来的,如果但我仍然看不到任何表格单元格中的所有空只是在导航栏上的姓名和空单元格。为什么它是空的anyidea?
你是正确的队友我删除了如果说法但仍然如果你想我可以把图像 –
解决方案不是删除if语句,而是添加'cell.detailTextLabel.text = show1'语句在if单元之后的单元格之上.textLabel.text = [array objectAtIndex:indexPath.row];'。您还可以检查当您尝试重新加载数据时show1的值是多少,并且是与您正在设置的背景颜色不同的详细文本颜色 –