2013-03-04 2 views
2

customCell (CustomCell) (2 개의 lables 및 하나의 ImageView가있는 CustomCell)로 UITableView를 사용하고 있습니다.상태에서 UITableViewCell의 색상을 변경하고 상태를 선택했습니다.

정상 모드에서는 모든 셀의 흰색이 필요합니다.

사용자를 눌러 특정 셀은 해당 셀의 다음 색상 (세포의 나머지 부분은 흰색이어야 함) 회색해야하는 경우

그리고 사용자 릴리스 경우 동일한 셀은 해당 셀의 색상은 오렌지 (나머지해야한다 세포는 흰색이어야 함)

어떻게 알아낼 수 있습니까?

나는 이것을 setSelectedBackground, willSelectRowAtIndexPath 및 Gestures 메소드를 사용하여 시도했다. 그러나 동일한 셀에 대해 이러한 3 가지 색상 상태를 볼 수 없습니다. 2 개 주 모두가 함께 노력하고 있습니다.

모든 아이디어 어떻게 동일한 기능을 얻을 수 있습니까?

나는 선택기를 사용하여 안드로이드에서 동일한 기능을 구현했습니다. iPhone에서 동일한 기능을 원합니다. 어떤 도움?

미리 감사드립니다. 당신이 다음

cell.selectionStyle=UITableViewCellSelectionStyleGray; 

회색 원하는 아니면 tableData을 다음 다음 previousSelected 인덱스 값을 저장했다 다시로드하지 않으려면 didSelectRow

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView reloadData]; 
    UITableViewCell *cell=(UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath]; 
    [cell setBackgroundColor:[UIColor orangeColor]]; 
} 

에 배경 색상을 설정할 수 있습니다 경우

+0

약간의 소스 코드를 제공하면 도움이됩니다. – aqua

+0

사용자 정의 셀보기를 사용합니까? – NANNAV

+0

@NANNAV 예 @ 사용자 정의 셀을 사용했습니다. –

답변

3

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //Make oreange cell 
    UITableViewCell *presentCell=(UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath]; 
    [presentCell setBackgroundColor:[UIColor orangeColor]]; 

    //make your previous cellBackgrod to clear, you can make it white as per your requirement 
    UITableViewCell *previouscell=(UITableViewCell*)[tableView cellForRowAtIndexPath:previousSelectedCellIndexPath]; 
    [previouscell setBackgroundColor:[UIColor clearColor]]; 

    //save your selected cell index 
    previousSelectedCellIndexPath=indexPath; 
} 
+0

하지만이 셀을 탭하면 탭을 해제 할 때만 흰색으로 되돌아갑니다. – Kasaname

+0

@ Rajneesh071 선택 색상. 누르지 않을 때 –

+0

@ Rajneesh071 작동 중입니다.하지만 문제는 tableView를 다시로드하면 테이블이 깜박입니다. 그러나 요구 사항에 따라 기능 –

7

사용자 정의 셀에이 두 가지 방법을 기입하십시오.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    self.contentView.backgroundColor=[UIColor greenColor]; 
} 
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 
    self.contentView.backgroundColor=[UIColor orangeColor]; 

} 
+0

내 마지막에는 작동하지 않습니다. ( –

+4

@AkbariDipali [super touchesEnded : touches withEvent : event]를 호출해야 할 수도 있습니다. –

+0

도 적절한 설정을 기억하십시오. background in touchesCancelled –

2

꽤 우아한 해결책은 tableViewCell의 setHighlighted : 메서드를 재정의하는 것입니다.

- (void)setHighlighted:(BOOL)highlighted { 
    [super setHighlighted:highlighted]; 
    if(highlighted) { 
    _backView.backgroundColor = [UIColor blueColor]; 
    } 
    else 
    { 
    _backView.backgroundColor = [UIColor blackColor]; 
    } 
} 

jQuery과 자동 YES 선택된 셀 highlighted @property 설정할 때 셀의 사용자 탭.

세포를 선택 취소하려는 경우 didSelect 테이블보기 대리인 메서드에서 [_tableView deselectCellAtIndexPath:indexPath animated:NO];을 호출하는 것을 잊지 마십시오!

+0

'highlighted = YES'와 함께 메서드가 호출되지 않습니다 .iOS9 시뮬레이터 – Ossir

관련 문제