2014-09-16 5 views
1
Code: 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

static NSString *cellIdentifier = @"cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
if(cell == nil){ 
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    cell.selectionStyle = UITableViewCellStyleDefault; 
} 
cell.contentView.backgroundColor = [UIColor clearColor]; 

cell.textLabel.text = @"testing"; 
if(indexPath.row == 1){ 
    cell.textLabel.textColor = UIColorMake(kOrangeColour); 
} 

return cell; 

} I가 storyboard.I 14 개 행이있는 tableview 내가 스크롤 .When 2 행 (IE1 인덱스)의 색상 변경 만들었고 많은 용의 tableview 아래가jQuery과 로우 색상 변경 스크롤 후

그때 나는 14 행 (ie 13 색인) 색상을 찾았습니다 .1 행과 14 행 모두 오렌지색입니다. 코드가 하나의 행 색상으로 변경되어야합니다. 왜 이런 현상이 발생합니까? 어떤 도움을 주시면 감사하겠습니다. 미리 감사드립니다.

+0

스크롤하는 동안 UITableViewCells가 재사용되고 있습니다. 행이 1이 아닌 경우 레이블의 원본 textColor를 복원해야합니다. –

답변

3

사용

if(indexPath.row == 1){ 
    cell.textLabel.textColor = UIColorMake(kOrangeColour); 
} else { 
    cell.textLabel.textColor = [UIColor whiteColor]; // change is here 
} 

대신 UITableViewCell의 재사용시

if(indexPath.row == 1){ 
    cell.textLabel.textColor = UIColorMake(kOrangeColour); 
} 

, 당신은 ifelse를 선언해야합니다.

+0

유용한 정보가 하나 있습니다 ... 멋진 색상 생성 클래스 인 https : //github.com/goppinath/GOExtendedUIColor (UIColorMake() 정의)보다 X11 정의 된 색상이 200 개 이상 있습니다. – Goppinath

+0

내 문제가 해결되었습니다. – user3823935