2012-01-31 6 views
1

왜 이것이 올바르게 작동하지 않는지 말할 수 있습니까?UIView 배경색이 적용되지 않습니다.

tableView:didSelectAtIndexRowPath: 메서드의 표보기 셀 내에 아래 코드 줄이 있습니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [[tableView viewWithTag:199]removeFromSuperview]; 

    CGSize cellSize = [tableView cellForRowAtIndexPath:indexPath].frame.size; 

    UIView *subSelectionView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, (int)cellSize.width - 20, 100)]; 

    [subSelectionView setBackgroundColor:[UIColor blueColor]]; 

    subSelectionView.layer.borderColor = [UIColor grayColor].CGColor; 
    subSelectionView.layer.borderWidth = 1; 

    subSelectionView.tag = 199;  

    [[tableView cellForRowAtIndexPath:indexPath]addSubview:subSelectionView]; 
} 

공지 코드 :

[subSelectionView setBackgroundColor:[UIColor blueColor]]; 

분명히, 나는 내가 UITableViewCell에 추가 된 서브 뷰의 색상을 변경하고 싶지만 왜 작동하지?

+0

'subSelectionView'가 테이블 뷰 셀의 콘텐트 뷰에 의해 커버되지 않는지 확인하십시오. – Costique

답변

2

나타나서는

[tableView deselectRowAtIndexPath:indexPath animated:NO]; 

그래서 UR 방법이 될 것

[[tableView cellForRowAtIndexPath:indexPath]addSubview:subSelectionView]; 

[tableview reloadData]; 
+0

감사합니다 .. 그것은 나를 위해 작동합니다 .. : D 당신이 두 대답 기뻤습니다 .. – Aldee

1

이 방법의 시작에 다음 줄을 추가 테이블에 하위 뷰를 추가 한 후 테이블을 다시로드

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:NO]; 

    [[tableView viewWithTag:199]removeFromSuperview]; 
    .... 
} 
관련 문제