带有UISearchBar的iPhone UITableView和刷新的Section Index

时间:2009-05-08 10:29:44

标签: iphone uitableview uisearchbar

我有一个顶部有UISearchBar的UITableView。

我还使用Section Index委托在右侧显示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]没有做到这一点)

万分感谢!

3 个答案:

答案 0 :(得分:4)

您应该在完全激活搜索时禁用索引绘制。只需在你的代表中返回nil,就像这样:

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

  ...
}

答案 1 :(得分:2)

您可以尝试使用

- (void)flashScrollIndicators

刷新滚动条,希望段索引呢?

答案 2 :(得分:0)

工作正常!!!

  

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