2012-03-23 2 views
1

다음 코드를 사용하여 TableView 색인을 표시하고 있습니다. 내 문제는 돋보기 아이콘을 누르면 검색 바가있는 테이블 맨 위로 이동하지 않는다는 것입니다. 색인의 다른 모든 섹션이 작동합니다.UiTableView 색인에서 돋보기 아이콘 누르기

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { 

if (tableView == [[self searchDisplayController] searchResultsTableView]) 
    return nil; 
else { 
    //I add the magnifying glass to the index 
    NSArray *indexArray = [NSArray arrayWithObject:UITableViewIndexSearch]; 
    // I return the array for the index after I add the rest of Index items 
    return [indexArray arrayByAddingObjectsFromArray:self.sectionsarray]; 
} 


} 


- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 
// I set index - 1 so I can compensate for the addition of the magnifying glass 
return index -1; 
} 

답변

2

-1 부분은 무엇입니까, 내가 모르는 당신이 테이블 헤더의 섹션 대신 다음 코드를 사용할 수 있습니다

if(index == 0)  
    [tableView scrollRectToVisible:CGRectMake(0, 0, self.mySearchBar.width, self.mySearchBar.height) animated:YES]; 
return index -1; 
+0

코드는 무엇입니까? –

+0

'-1' 인덱스 섹션이 없으므로 인덱스 0 (글래스 아이콘)으로 제목을 선택하면 원하는 것을 할 수 없습니다. 대신 수동으로 해당 사례를 처리하고 스크롤 막대보기 콘텐츠를 검색 창이있는 왼쪽 상단으로 스크롤해야합니다. 이것이'sectionForSectionIndexTitle' 메소드의 내용입니다. –

+0

좋은 해결책. 나는 애니메이 티드를 사용하기로 결정했다. 그러나 이것은 연락처 앱과 같은 결과를 주었다. 또한 검색 막대에 IBOutlet이 없기 때문에 임의의 크기의 rect가 x = y = 0 인 동안 ok로 보입니다. – Ants