2009-05-08 12 views
6

私はUITearchViewの上部にUISearchBarを持っています。iPhone UITearchViewでUITearchBarを更新し、セクションインデックスを更新する

また、セクションインデックスデリゲートを使用して、右側にABC ... XYZを表示します。

検索ボックスをクリックすると問題が発生し、キーボードが下部から表示され、セクションインデックスが縮んでA D ... * Zのみが表示されます。検索を終了してキーボードが消えたときスクロールするか、または類似するまで、インデックスはこの「つぶれた」状態にとどまります。

// 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です:( –

関連する問題