2011-08-04 82 views
0
- (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?

回答

3

代码“cell.detailTextLabel.text = show1;”是否在if的条件之内if(cell == nil) 如果单元格已经可用,重新加载单元格时,将不会进入代码块,并且您更改show1的值将不会显示。

代码
cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];

检查,如果他们的是,它可以重复使用的单元。如果它发现它会返回相同的

+0

你是正确的队友我删除了如果说法但仍然如果你想我可以把图像 –

+1

解决方案不是删除if语句,而是添加'cell.detailTextLabel.text = show1'语句在if单元之后的单元格之上.textLabel.text = [array objectAtIndex:indexPath.row];'。您还可以检查当您尝试重新加载数据时show1的值是多少,并且是与您正在设置的背景颜色不同的详细文本颜色 –

3

字符串值Show1仅在初始化单元时设置。

cell.detailTextLabel.text=show1; 

把上面的行放在这一行下面并检查。

cell.textLabel.text = [array objectAtIndex:indexPath.row]; 
+0

你是正确的队友,但我仍然无法看到它的细胞仍然空白没有细胞在它 –