2013-05-08 4 views

답변

2

이 줄을 추가 후 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSString *cellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
} 
[cell.contentView setBackgroundColor:[UIColor blueColor]];  
cell.textLabel.text = [NSString stringWithFormat:@"%@", [cat objectAtIndex:indexPath.row]];  
return cell;} 

내 화면 캡처이있다 [cell.contentView의 setBackgroundColor : [UIColor blueColor]]; 라인 :

cell.textLabel.backgroundColor = [UIColor clearColor]; 
1

답변 : 방식 때문에 UITableViewtableView:willDisplayCell:forRowAtIndexPath:

- (void)tableView:(UITableView *)tableView 
    willDisplayCell:(UITableViewCell *)cell 
forRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     cell.backgroundColor = [UIColor blueColor]; 
    } 
1

이 선택하는 동안 셀의 배경 색상을 변경, 당신은 tableView:willDisplayCell:forRowAtIndexPath:를 구현하고 거기에 셀 배경을 설정해야합니다. contentView뿐만 아니라 전체 셀의 배경을 설정해야합니다. 그렇지 않으면 액세서리보기가 강조 표시되지 않습니다.

- (void)tableView:(UITableView *)tableView 
    willDisplayCell:(UITableViewCell *)cell 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // ... 
    cell.backgroundColor = ...; 
} 

셀의 다양한 하위보기에 투명한 배경색이 있어야 할 수도 있습니다.

cell.titleLabel.backgroundColor = [UIColor clearColor]; 
cell.titleLabel.opaque = NO; 
1

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSString *cellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
} 
[cell.contentView setBackgroundColor:[UIColor blueColor]];  
cell.textLabel.backgroundColor = [UIColor clearColor]; 
cell.textLabel.text = [NSString stringWithFormat:@"%@", [cat objectAtIndex:indexPath.row]];  
return cell;} 
관련 문제