2012-12-11 4 views
1

안녕하세요 모든 사람들이 ios에 상당히 새롭기 때문에 배울 점이 많습니다. 웹 서비스에서 표 셀로의 동적 배경색이있는 하위보기를 추가했지만 하위보기 배경색은 선택되어 있습니다. 표 셀을 선택한 상태 색으로 변경하면 모든 하위보기를 배경 색이보기로 변경하는 이유는 무엇인지 알기 때문에 하위보기 배경색을 변경하지 못하도록 막을 수 있습니다. 선택한 동적 색상으로 유지 되나요?목표 c 하위 뷰 UITableViewCell 배경색 선택시

array = [colors objectAtIndex:indexPath.row]; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 

     UIView *colorBox = [[UIView alloc] initWithFrame:CGRectMake(10,10,20,20)]; 
     [colorBox setTag:1];    
     [cell.contentView addSubview:colorBox]; 
    } 

UIView *box = [cell viewWithTag:1]; 
box.backgroundColor = [self colorForBox:array.color]; 

return cell; 

는 다음 색상 어떤 도움이 많이 감사 감사하겠습니다

- (UIColor *)colorForTransport:(NSString*)Line { 

if([Line isEqualToString:@"Brown"]) 
    return [UIColor colorWithRed:0.682 green:0.38 blue:0.094 alpha:1]; 

else if([Line isEqualToString:@"Red"]) 
    return [UIColor colorWithRed:0.894 green:0.122 blue:0.122 alpha:1]; 

else 
    return DefaultBackgroundColor; 
} 

을 받고!

+0

내가 질문을 이해하지 않습니다. 너는 무엇을 막으려 고하는거야? – Lefteris

답변

0

찾고있는 색상 변경을 얻으려면 tableBackview의 selectedBackgroundView 하위보기를 변경해보십시오.

0

당신이 일반 스타일 테이블을 사용하는 경우, 당신이 원하는 배경 색상을 가진 ALLOC-init를 새로운 UIView의 필요하고 selectedBackgroundView에 할당됩니다 해당 속성에 대한 자세한 정보를 원하시면 http://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableViewCell/selectedBackgroundView를 참조하십시오 .

또는 뭔가처럼,

cell.selectionStyle = UITableViewCellSelectionStyleGray; 
0

당신의 UIView를 상속 새로운 서브 클래스를 생성 할 수 있습니다. 그런 다음 setBackgroundColor를 재정 의하여 아무 일도하지 않습니다. 그리고 배경색을 설정할 고유 한 메서드를 추가하십시오. 그런 식으로 시스템에서 사용자의 배경 색상을 무시 할 수 없습니다 당신은 당신의 새로운 방법 :

-(void) setBackgroundColor:(UIColor *)backgroundColor 
{ 
    //do nothing 
} 

//System do not know this method :) 
-(void) mySetBackgroundColor:(UIColor *)backgroundColor 
{ 
    [super setBackgroundColor:backgroundColor]; 
} 
0

있는 UITableViewCell 어떤 이유로 선택에 모든 서브 뷰의 backgroundColor로 변경을 사용하여 색상을 설정할 수 있습니다.

이 도움이 될 수 있습니다 :

DVColorLockView

관련 문제