2011-08-04 8 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でデータをリロードするとわかります。show1は、detailLabel.text内のtableViewのセルに配置する必要があるデータです。さて、私の奇妙な細胞の部分は、それが使えないatmを見ないでください。私は1つのセルとその偶数セルしか持っていません。私の問題は、[self.tableView reloadData]を削除するときです。私はそれを置くときに私はtableViewのセルを見ることができないそのすべての空のアイデアなぜ?どこが間違っているの?reloadDataはテーブルビューでセルを描画しません

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(cell == nil)のif条件の内側にある セルが既に使用可能である場合にセルをリロードすると、コードブロックに入っておらず、show1の値を変更しても表示されません。

コード
cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];

チェックし、それを再使用することができ、細胞は、彼らの場合。それが見つかった場合、それは同じを返す

+0

あなたは右の仲間です私は、あなたは私が画像を置くことができる場合、空のページを参照してください。 –

+1

解決策はif文を削除するのではなく、 'cell.detailTextLabel.text = show1'の文を' cell .textLabel.text = [配列objectAtIndex:indexPath.row]; '。また、データを再読み込みしようとしているときにshow1の値が何であるかを確認することができます。設定している背景色とは異なる詳細テキスト色です –

3

文字列値Show1は、セルの初期化中にのみ設定されます。

cell.detailTextLabel.text=show1; 

この行をこの行の下に置き、チェックします。

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

あなたは右の仲間ですが、私はまだそれがまだ空白の空を見ることができませんそれにはセルがありません –

関連する問題