2013-09-30 4 views
0

EDIT : 이것을 설명 할 때 명확하지 않았습니다. 내가로드하는 UITableView는 UITableView의 xib가 아닙니다. UITableView가 포함 된 사용자 정의 UIView입니다 (대리자 및 콘센트 및 기타 등등).iOS : nib의 TableView - 배경색 설정

배경색을 설정하려고합니다. 닙에서로드 된 tableview의 UITableViewCell.

먼저 tableView 배경색 속성을 UIColor clearColor로 설정해 보았습니다. 내가 시도 문서에 따라,

- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"scoreCell"; 

UITableViewCell *cell = [tableView 
         dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleSubtitle 
      reuseIdentifier:CellIdentifier]; 
} 

//First try 
cell.backgroundColor = [UIColor clearColor]; 

//Added this after the others didn't work 
cell.contentView.backgroundColor= [UIColor clearColor]; 

//Added this after 
cell.textLabel.backgroundColor = [UIColor clearColor]; 
cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 
// Configure the cell. 

cell.textLabel.text = [[leaderInfo objectAtIndex:indexPath.row] objectForKey:@"name"]; 
cell.detailTextLabel.text = [[[leaderInfo objectAtIndex:indexPath.row] objectForKey:@"score"] stringValue]; 
cell.textLabel.adjustsFontSizeToFitWidth =YES; 


return cell; 

} 그런 다음

가 작동하지 않았다 후 :

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
//Properties tested in all permutations 
    cell.backgroundColor=[UIColor clearColor]; 
    cell.textLabel.backgroundColor = [UIColor clearColor]; 
    cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 
} 

답변

0

에서 그 그럼 난 그렇게처럼 내 cellForRowAtIndexPath을 변경, 작동하지 않았다 순서를 설정하려면 셀 색상을 설정하려면 tableView의 배경색을 지우고 backgroundView를 nil로 설정해야합니다.

- (void)viewDidLoad 
{ 
    [self.tableView setBackgroundColor:[UIColor clearColor]]; 
    [self.tableView setBackgroundView:nil]; 
} 
+0

펜촉에 viewDidLoad가 없지만 아이디어가 옳습니다. 나는보기 자체가로드되기 전에 물건을 설정하고있었습니다. – JoshDG