2009-05-08 2 views
6

상단에 UISearchBar가있는 UITableView가 있습니다.iPhone UITearchView와 UISearchBar 및 새로 고침 섹션 색인

또한 섹션 인덱스 대리인을 사용하여 오른쪽에 ABC ... XYZ를 표시합니다. 내가 검색 상자를 클릭하고 키보드가 바닥에서 올라 오는

문제, 섹션 인덱스 과즙 그렇게 만 D이 ... * Z가 표시되어 발생 - 나는 검색을 닫고 그들은 키보드가 사라질 때 , 스크롤 할 때까지 색인이 "squashed"상태로 유지됩니다.

// animate the searchbar 
[UIView beginAnimations:nil context:NULL]; 
CGRect tempRect = [[self searchBar] frame]; 
tempRect.size.width = 320-kMarginRight; 
[[self searchBar] setFrame:tempRect]; 
[UIView commitAnimations]; 

    // animate the search index back into view 
for (UIView *view in [[self tableView] subviews]) { 
    if ([view respondsToSelector:@selector(moveIndexIn)]) { 
     MovableTableViewIndex *index = (MovableTableViewIndex*)view; 
     [index moveIndexIn]; 
    } 
} 

    // try a whole load of stuff to try and get the section indexes to draw again properly 
    // none of which work! 

[searchBar setText:@""]; 
[searchBar resignFirstResponder]; 

letUserSelectRow = YES; 
searching = NO; 
[[self navigationItem] setRightBarButtonItem:nil]; 
[[self tableView] setScrollEnabled:YES];   
[[self tableView] reloadData]; 
[[self tableView] flashScrollIndicators]; 
[[self tableView] sizeToFit]; 
[[self tableView] zoomScale];  
[[self tableView] reloadSectionIndexTitles]; 

내 질문에 대한 답변을 드리겠습니다. RHS에서 섹션 인덱스를 다시 그리는 방법이 있습니까 ([[self tableView] reloadData]은 트릭을하지 않습니다)

감사합니다.

답변

4

검색이 모두 활성화 될 때 인덱스 그리기를 비활성화해야합니다. 델리게이트에서 무언가를 반환하기 만하면됩니다 :

 
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { 
    if ([self.searchDisplayController isActive]) return nil; 

    ... 
} 
2

당신은 스크롤 너무 잘하면 섹션 인덱스를 새로

- (void)flashScrollIndicators 

를 사용하려고 할 수 있을까?

+0

은 내가 사용하고있는 정확한 코드 ... 아무 소용이 보여 내 위의 게시물을 편집했습니다! – adam

1

잘 작동합니다!

[searchBar setContentInset:UIEdgeInsetsMake(5, 0, 5, 35)];

+0

이것은 실제로 나를 위해 일했지만 유감스럽게도 문서화되지 않은 API입니다. –