2011-11-11 3 views
1

내 응용 프로그램에서 TableView가 있고 구분선의 높이와 색을 변경해야했습니다. 그래서 여기에서 브라우징하면 해결 방법을 찾을 수있었습니다. 그래서 나는 기본적으로 내 셀에있는 UIView를 추가하고 "가짜"구분자로 이것을 사용하고 있습니다 :UITableViewCell 및 행 선택 색상으로 구분 기호로 UIView

UIView *colorSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, 53, cell.frame.size.width, 4)]; 
    colorSeparator.backgroundColor = [UIColor yellowColor]; 
    [cell.contentView addSubview:colorSeparator]; 
    [colorSeparator release]; 

을하지만 지금은 행이 도청 될 때, 선택 색상 내 가짜 분리 적용 것으로 나타났습니다. 아무도 그것을 피할 수있는 방법을 알고 있습니까? 귀하의 시간에 대한 조언에 Thx :

답변

2

setSelected:animated:setHighlighted:animated: UITableViewCell의 방법으로 구분 기호의 색상을 복원 할 수 있습니다.

// just edited your function, it was missing a square bracket 
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 
    UIColor *c = [[colorSeparator.backgroundColor retain] autorelease]; 
    [super setHighlighted:highlighted animated:animated]; 
    colorSeparator.backgroundColor = c; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    UIColor *c = [[colorSeparator.backgroundColor retain] autorelease]; 
    [super setSelected:selected animated:animated]; 
    colorSeparator.backgroundColor = c; 
} 
+0

많은 Thx! 그래서 내가 UITableViewCell sublcass하고이 두 가지 메서드를 재정의해야합니까? –

+0

예, UITableViewCell의 하위 클래스를 만들고이 메서드를 재정의하고 새 클래스의 개체를 UITableView 대리자 메서드에서 반환해야합니다. –

+0

thx, 작동합니다! 당신에게 투표하십시오! –

관련 문제