2012-08-09 4 views
0

항목 목록이있는 표보기가 있습니다. 해당 항목 중 하나를 클릭하면 배경이 강조되기를 원합니다. 그 코드는 작동하지만 클릭 자체가 아닌 출시시 색상이 바뀝니다. 사용자가 셀을 탭할 때 강조 표시하고 셀을 놓을 때 강조 표시하지 않으려면 어떻게해야합니까? 나는 그것이 버튼처럼 일 할하이라이트 표보기 셀 (클릭시) (릴리스가 아님)

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    // Navigation logic may go here. Create and push another view controller. 

    Help_Cell *cell =(Help_Cell*) [tableView cellForRowAtIndexPath:indexPath]; 

    cell.selectionStyle=UITableViewCellSelectionStyleNone; 

    UIView *v=[[UIView alloc] initWithFrame:cell.frame]; 

    v.backgroundColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor2"]]; 

    cell.backgroundView=v; 

    cell.title.textColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor1"]]; 
} 

:

여기 내 코드입니다. didSelectRowAtIndexPath 외에도 UITableView 또는 UITableViewCell에 대해 onClick 메서드가 있습니까? 여기에 편집

이 cellForRowAtIndexPath에, 세포를 만드는 때 cellForRowAtIndexPath

-(void)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    Help_Cell *cell =(Help_Cell*) [tableView cellForRowAtIndexPath:indexPath]; 

    cell.selectionStyle=UITableViewCellSelectionStyleNone; 

    UIView *v=[[UIView alloc] initWithFrame:cell.frame]; 

    v.backgroundColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor2"]]; 

    cell.selectedBackgroundView=v; 

} 

답변

2

에서 내 코드, 코드 아래의 총수 :

UIView *v=[[UIView alloc] initWithFrame:cell.frame]; 
v.backgroundColor = [self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor2"]]; 
    cell.selectedBackgroundView = v; 

아무것도 쓸 필요를 didSelectRow 메소드에서.

+0

로 이것을 고려할 수 있습니다. 백그라운드 뷰에 다른 'UIView v'가 설정되어 있다면 영향을받을까요? – BigT

+0

selectedBackgroundView에 추가해야합니다. backgroundView가 아닙니다. 다른보기가 backgroundView로 있으면 아무 문제가 없습니다. 일부 코드도 게시하여 확인할 수 있습니다. – Apurv

+0

내 편집을 확인하십시오. 그게 내가 너의 제안에 담긴 것. – BigT

0

당신은 내가 그 생각하지만 내`cellForRowAtIndexPath`으로 작동하지 않는 추가를 원하는 옵션

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

[tableView selectRowAtIndexPath:indexPath.row animated:YES scrollPosition:UITableViewScrollPositionTop]; 

} 
관련 문제