2013-07-25 2 views
0

UITableView 섹션 색인의 색상을 사용자가 클릭하면 변경됩니다.사용자가 UITableView를 클릭하면 알림을받을 수 있습니까? sectionIndex

sectionIndexColorsectionIndexTrackingBackgroundColor은 tableview 및 다른 상태를 초기화하는 동안 설정할 수 있지만 클릭 할 때 색인 색을 변경할 수있는 방법을 찾지 못했습니다.

업데이트 :

큰 테이블 뷰에서는 A-Z 사이드 바를 의미합니다.

enter image description here

선택한 상태 : enter image description here

+0

셀 색상 변경 ... 또는 섹션 선택을 선택한 다음 섹션 색상 변경을 의미합니까? –

+0

전체 색인 또는 선택한 항목의 색상을 변경 하시겠습니까? –

+0

@Jonathan Cichon : 전체 색인 만. 선택되지 않은 상태에서는 어두운 색을, 선택된 상태에서는 밝은 색을 가져야합니다. – AlexVogel

답변

1

사과가 공개 API를 사용하여 지원하지 않기 때문에 나는 이것에 대한 오히려 더러운 해결책이 있습니다. 내 구현 작업은 훌륭하게 종료되며 향후 일부 API가 변경되면 충돌이 발생하지 않아야합니다 (더 이상 작동하지 않음). UITableView을 서브 클래 싱하는 중이며 테이블에 서브 뷰로 추가 될 때 sectionIndex 뷰에 자체 콜백을 추가합니다.

@interface MyTableView : UITableView 

@end 

@implementation MyTableView 

- (void)selectionStarted { 
    [self setSectionIndexColor:[UIColor greenColor]]; 
} 

- (void)selectionStoped { 
    [self setSectionIndexColor:[UIColor redColor]]; 
} 

- (void)addSubview:(UIView *)view { 
    [super addSubview:view]; 
    if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewIndex"] && [view isKindOfClass:[UIControl class]]) { 
     UIControl *cont = (UIControl *)view; 
     [cont addTarget:self action:@selector(selectionStarted) forControlEvents:UIControlEventTouchDown]; 
     [cont addTarget:self action:@selector(selectionStoped) forControlEvents:UIControlEventTouchUpInside]; 
     [cont addTarget:self action:@selector(selectionStoped) forControlEvents:UIControlEventTouchUpOutside]; 
     [cont addTarget:self action:@selector(selectionStoped) forControlEvents:UIControlEventTouchCancel]; 
    } 
} 

@end 
+0

좋은 해결책이지만, 개인 api를 사용하여 앱을 거부 할 수는 없습니다. – AlexVogel

+0

당신은 개인 api를 호출하지 않으므로 사과가 그것을 거부 할 것이라고 생각하지 않습니다. –

0

사용 UITableView 위임 다음

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

필요 임의로 변경 여기 (이미지 2에서 회색 막대 참조)

이 이

이 선택하지 않은 상태가 일부 이미지입니다 섹션에 indexPath가 있습니다.

가장 쉬운 방법은 indexPath를 속성으로 유지하고 tableView을 다시로드 한 다음 viewForHeaderInSection에서 indexPath와 원하는 색상을 비교해야합니다.

관련 문제