2011-08-06 20 views
0

セル背景色が常にクリアカラーになる問題があります。私は、灰色、テーブルビューの背景色をクリアするために背景色を設定し、色をクリアするためにtableviewcellの背景色を設定しなかった。しかし、細胞の背景は常に灰色で表示されます。誰にでもこれについて何か考えてもらえますか?uitableviewcell背景色がクリアカラーになる

おかげ

enter image description here

-(void)viewDidLoad 
{ 
    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"TableBackGround.png"]]; 

    Acc_Details_TView.backgroundColor = [UIColor clearColor]; 
    Acc_Details_TView.rowHeight = 40; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"TransCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    switch ([Acc_Details_SegCtrl selectedSegmentIndex]) { 
     case 0:{ 
      if (cell == nil) { 
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableCell"] autorelease]; 
       cell.backgroundColor =[UIColor clearColor]; 
       cell.textLabel.font = [UIFont boldSystemFontOfSize:14]; 
       cell.detailTextLabel.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Date"]; 
       cell.detailTextLabel.font = [UIFont systemFontOfSize:12]; 
      } 
      NSString *titleName =[[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Title"] ; 
      if ([titleName length] > 19) { 
       cell.textLabel.text = [titleName substringWithRange:NSMakeRange(0, 20)];     
      } 
      else{ 
       cell.textLabel.text = titleName; 
      } 

      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
      UILabel * acc_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 5, 60,10)]; 
      acc_Amount.textAlignment = UITextAlignmentRight; 
      acc_Amount.backgroundColor = [UIColor clearColor]; 
      acc_Amount.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Amount"]; 
      acc_Amount.font = [UIFont boldSystemFontOfSize:14]; 
      [cell.contentView addSubview:acc_Amount]; 
      UILabel * balance_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 23, 60,10)]; 
      balance_Amount.textAlignment = UITextAlignmentRight; 
      balance_Amount.text = @"$1234.50"; 
      balance_Amount.backgroundColor = [UIColor clearColor]; 
      balance_Amount.textColor = [UIColor grayColor]; 
      balance_Amount.font = [UIFont systemFontOfSize:12]; 
      [cell.contentView addSubview:balance_Amount]; 
      return cell;    
     } 
    } 
} 
+0

画像が役に立ちます。 – Legolas

答えて

4

セルは正確に透過的ではありません。 UITableViewのbackgroundColorを設定すると、文書化されていないものがあります。これは、あなたがこのような何かを得るこれにより[UIColor colorWithWhite:0.5 alpha:0.5]のようないくつかの半透明色に設定することで参照するための最良の方法:あなたの問題を解決するために

weird table view

を、あなたは細胞のcontentView.backgroundColorを設定する必要がありますし、 tableViewの設定後、すべてのサブビューのbackgroundColors。ここにあなたのcellForRowAtIndexPathは次のようになります。これを更新:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"TransCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    UIColor *cellBackgroundColor = [UIColor whiteColor]; 

    switch ([Acc_Details_SegCtrl selectedSegmentIndex]) { 
     case 0:{ 
      if (cell == nil) { 
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableCell"] autorelease]; 
       cell.textLabel.font = [UIFont boldSystemFontOfSize:14]; 
       cell.detailTextLabel.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Date"]; 
       cell.detailTextLabel.font = [UIFont systemFontOfSize:12]; 
       cell.accessoryView.backgroundColor = cellBackgroundColor; 
       cell.backgroundView.backgroundColor = cellBackgroundColor; 
       cell.contentView.backgroundColor = cellBackgroundColor; 
       cell.textLabel.backgroundColor = cellBackgroundColor; 
       cell.detailTextLabel.backgroundColor = cellBackgroundColor; 
       UIView *backView = [[UIView alloc] initWithFrame:cell.frame]; 
       backView.backgroundColor = cellBackgroundColor; 
       cell.backgroundView = backView; 
       [backView release]; 
      } 
      NSString *titleName =[[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Title"] ; 
      if ([titleName length] > 19) { 
       cell.textLabel.text = [titleName substringWithRange:NSMakeRange(0, 20)];     
      } 
      else{ 
       cell.textLabel.text = titleName; 
      } 

      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
      UILabel * acc_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 5, 60,10)]; 
      acc_Amount.textAlignment = UITextAlignmentRight; 
      acc_Amount.backgroundColor = cellBackgroundColor; 
      acc_Amount.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Amount"]; 
      acc_Amount.font = [UIFont boldSystemFontOfSize:14]; 
      [cell.contentView addSubview:acc_Amount]; 
      UILabel * balance_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 23, 60,10)]; 
      balance_Amount.textAlignment = UITextAlignmentRight; 
      balance_Amount.text = @"$1234.50"; 
      balance_Amount.backgroundColor = cellBackgroundColor]; 
      balance_Amount.textColor = [UIColor grayColor]; 
      balance_Amount.font = [UIFont systemFontOfSize:12]; 
      [cell.contentView addSubview:balance_Amount]; 
     } 
    } 
    return cell; 
} 
+0

このコードを使用すると、シェブロン周辺の領域はまだ灰色で表示されます。だから、cell.accessoryview.background = cellBackgroundColorを追加してみましたが、それでも動作しませんでした。どのようなアイデアが間違っている。私はUITableViewCellStyleValue2スタイルを使用しています。 – pa12

+0

その場合、 'cell.detailTextLabel.backgroundColor = cellBackgroundColor;'を追加する必要があります。まだ動作していない場合は、スクリーンショットをアップロードしてください。 –

+0

変更を加えた後、あなたに伝えました。私はコードに画像を追加しました。それを見てください。それが私の表のセルがどのように現れるかです。 – pa12

0

私はあなたの質問を理解していませんでした。テーブルの背景をグレーに設定してからクリアしますが、グレーに設定しても灰色で表示されませんでした。

table.backgroundColor = [UIColor clearColor]; 
+0

私は自分のuiviewの背景色を灰色に、私のテーブルビューを色をクリアに設定しました。 – pa12

5

はメソッドではなく、あなたのcellForRowAtIndexPath:方法に比べ

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

であなたのセルの背景色を設定してみてください。

+0

これは私がこの問題に遭遇したときの過去の私の問題を解決しました。 – mjdth

+0

これはうまくいきましたが、問題はnumberOfRowsInSectionで指定したセルの数の色を設定しますが、テーブルビューのすべてのセルではありません。だから私の半分は白く、残りは灰色に見える。 – pa12

+0

アップルのドキュメント**は具体的には「cellForRowAtIndexPath」ではなく、このメソッドを使用するように指示しています。 – yujean

関連する問題