2012-04-04 2 views
2

셀의 완전히 다른 2 가지 모양 (및 내용)을 설정하고 싶습니다. (하나는 선택되고 하나는 선택되지 않음).UITableView 셀 : backgroundBack을 표시하지 않고 selectedBackgroundView

이 코드는 작동하지만 선택한 셀의 이미지가 50 % 투명하기 때문에 맨 아래에 BackgroundView가 표시됩니다.

clearBackgroundView는 선택된 경우에만 표시되는 요소로 셀을 채우는 좋은 방법을 제공합니다. BackgroundView 셀을 채우는 것보다 다른 위치가되어, 위치는 어떻게

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *cellIdentifier = @"hello"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
    } 


    UIImage *image = [UIImage imageNamed:@"listview_btn.png"]; 
    UIImage *imageThumb = [UIImage imageNamed:@"01_thumb.jpg"]; 
    UIImageView* imageView = [[UIImageView alloc] initWithImage:imageThumb]; 
    [imageView setFrame:CGRectMake(0, 0, 50, 67)]; 
    [cell setBackgroundView:[[UIImageView alloc]initWithImage:image] ]; 
    [cell.backgroundView addSubview:imageView]; 



    UIImage *imageSel = [UIImage imageNamed:@"listview_btn_on.png"]; 
    UIImage *imageThumbSel = [UIImage imageNamed:@"01_thumb_Sel.jpg"]; 
    UIImageView* imageViewSel = [[UIImageView alloc] initWithImage:imageThumbSel]; 
    [imageViewSel setFrame:CGRectMake(110, 0, 50, 67)]; 
    [cell setSelectedBackgroundView:[[UIImageView alloc]initWithImage:imageSel] ]; 
    [cell.selectedBackgroundView addSubview:imageViewSel]; 
+0

코드 서식을 수정하기 위해 한 번의 클릭 만 필요했습니다. 어쩌면 다음 번에 클릭하면됩니다. 이렇게하려면 질문에 삽입 한 코드를 모두 선택하고'{}'버튼을 누릅니다. 코드가 읽기 쉽고 좋은 색 구성표를 얻을 수 있도록 적절한 markdown 들여 쓰기가 추가됩니다 :-) –

+1

물론 xcode가 아닌 [Xcode] (http://stackoverflow.com/a/5725282/457406)입니다. Xcode는 iPhone이 아닙니다. Xcode는 IDE 일뿐 아니라 코드를 작성하는 도구입니다. 귀하의 질문이 IDE 자체와 관련이 없다면 (예 : "Xcode에서 줄 번호를 어떻게 켜야합니까?") –

+0

이 질문에 대한 답변이 없습니까? (Matthias에게 감사드립니다) – Franck

답변

0

선택한 배경 뷰가 불투명 확인 selectedBackgroundView에 표시되지 않습니다. 항상 배경보기 위에 삽입되므로 Photoshop 또는 다른 그래픽 편집기에서 합성하고 결과를 선택한 배경보기로 사용할 수 있습니다. 이 방법을 (난 아직도 매우 추천) 감당할 수없는 경우

, 당신은 UITableViewCell를 서브 클래스 및/선택 강조 할 때 무기 호에 배경보기 속성을 설정 및/강조 표시되지 않은 선택 해제 할 때를 복원 setHighlighted:animatedsetSelected:animated 모두를 대체 할 수 있습니다. 그러나 그것은 훨씬 더 복잡한 접근 방법입니다.