2009-10-01 6 views
8

펜촉에서 맞춤 UITableViewCell을 사용합니다. 액세서리 뷰는 Detail Disclosure Indicator입니다. 문제는 액세서리보기 뒤에있는 UITableViewCell의 배경색이 렌더링되지 않는다는 것입니다 (아래 이미지/소스 참조). 모든 단서? 작동하지 않았다UITableViewCell에서 투명 액세서리보기를 얻는 방법? (스크린 샷 포함)

것들 : 또한, 여기에 내가 시도했지만 작동하지 않았다 몇 가지 있습니다
- clearColor
에 액세서리보기의 backgroundColor로 설정 - 셀의에 contentView.opaque 설정 FALSE
- 셀


,174에 대한 기본이 아닌 액세서리보기를 설정 - FALSE
에 테이블 뷰의 contentView.opaque 설정

alt text http://www.chicknchoke.com/so/IMG_8028.png

-(void)showTablePrep 
    { 
     myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 480, 320, 416) style:UITableViewStylePlain]; 
     myTableView.dataSource = self; 
     myTableView.delegate = self; 
     myTableView.delaysContentTouches = FALSE; 
     myTableView.opaque = FALSE; 
     myTableView.rowHeight = 60; 

     [UIView beginAnimations:@"SlideUp" context:nil]; 
     [UIView setAnimationDuration:0.3f]; 

     [myTableView setCenter:CGPointMake(myTableView.center.x, myTableView.center.y-436)]; 
     [self.view addSubview:myTableView]; 
     [self.view bringSubviewToFront:myTableView]; 

     [UIView commitAnimations]; 


    } 




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

    FriendsCell* cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCellID"]; 

    if (cell == nil){ 

     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FriendsCellView" owner:self options:nil]; 

     cell = (FriendsCell*)[nib objectAtIndex:0]; 

     if(indexPath.row % 2 == 0){ 

     cell.contentView.backgroundColor = [UIColor grayColor]; 


     }else{ 

     cell.contentView.backgroundColor = [UIColor lightGrayColor]; 


     } 
     cell.accessoryView.backgroundColor = [UIColor clearColor]; 
     cell.contentView.opaque = FALSE; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 


    if(f 

riendsCounter > indexPath.row){ 


      cell.titleLabel.text = @"Label"; 
      cell.descLabel.text = @"Description goes here"; 

     }else{ 

      cell.titleLabel.text = @""; 
      cell.descLabel.text = @""; 
      cell.accessoryType = UITableViewCellAccessoryNone; 

     } 

     } 

     return cell;  
    } 

답변

11

당신은 잘못 셀의 배경 색상을 그리는 것입니다. UITableViewCellcontentViewaccessoryView이 나란히 나란히 배치됩니다. (이 작업은 contentView이 내용을 잘라서 액세서리보기와 겹쳐지지 않도록하기 위해 수행됩니다.) 액세서리보기가 불투명하지 않은 것은 회색 배경이 액세서리보기 뒤에 단순히 그려지지 않는다는 것입니다.

UITableViewCell 뒤에 그려진 배경을 사용자 정의하는 올바른 방법은 backgroundView을 사용자 정의하는 것입니다. 나는 이것을 시도하지는 않았지만 색상 만 바꾸고 있기 때문에 backgroundView에있는 backgroundColor 색상을 원하는 색상으로 간단히 설정할 수 있습니다.

+0

을 'UITableView' 드로잉을 커스터마이징하는 것에 대한 정말 멋진 개관은 다음과 같습니다 : http://cocoawithlove.com/2009/04/easy-custom-uitab leview-drawing.html – Alex

+7

나를 위해 일했습니다 : 세포.backgroundView = [[UIView alloc] init]; cell.backgroundView.backgroundColor = [UIColor yellowColor]; – joshaidan

+1

@joshaidan ARC를 사용하지 않는 한 생성 한 뷰를 공개하는 것을 잊지 마십시오. cell.backgroundView = [[[UIView alloc] init] autorelease]; – manicaesar

1

내 사용자 지정 테이블보기 셀의 하위 뷰를 살펴보면 대답을 찾았습니다.

액세서리보기에는 버튼이 있습니다. 하위보기에서이 버튼을 찾아 색상을 변경하면 액세서리 버튼 뒤의 배경색을 업데이트 할 수있었습니다.

<UIButton: 0x3b4d690; frame = (277 0; 43 75); opaque = NO; layer = <CALayer: 0x3b3e0b0>> 

for (UIView *aSubView in self.subviews) { 
    if ([aSubView isMemberOfClass:[UIButton class]]) { 
     aSubView.backgroundColor = [UIColor greenColor]; 
    } 
} 

불행히도 난 단지 내 사용자 정의 테이블 뷰 셀 클래스의

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 

메서드 내에서이 버튼을 도달 할 수 있었다. 사용자가 셀을 선택할 때 다른 하이라이트 색상을 표시하기 위해 내 응용 프로그램 내에서 이것을 성공적으로 사용했습니다. 이것은 올바른 방향으로 당신을 가리켜 야합니다.

0

나는이 iOS7에에 문제가 있지만 추가

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

에서

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

를 해결하고 당신은 당신의 배경과 여기에 다른 bakcgrounds 수정 : 나는 또한이 있다고 언급하고 싶었

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Add your Colour. 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [cell setBackgroundColor:[UIColor colorWithHexColor:HIGHLIGHT_COLOR]]; 
} 

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Reset Colour. 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [cell setBackgroundColor:[UIColor colorWithHexColor:UNHIGHLIGHT_COLOR]]; 
}