代码之家  ›  专栏  ›  技术社区  ›  adam

带UISearchBar和刷新节索引的iPhone UITableView

  •  6
  • adam  · 技术社区  · 17 年前

    我有一个UITableView,顶部有一个UISearchBar。

    我还使用节索引委托在右侧显示ABC…XYZ。

    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 回复  |  直到 17 年前
        1
  •  4
  •   Boon    16 年前

    当搜索全部激活时,应禁用中的索引绘制。只需在委托中返回nil,如下所示:

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
      if ([self.searchDisplayController isActive]) return nil;
    
      ...
    }
    
        2
  •  2
  •   h4xxr    17 年前

    你可以尝试使用

    - (void)flashScrollIndicators
    

    这会刷新滚动条,希望还会刷新节索引?

        3
  •  0
  •   Oscar    16 年前

    它工作得很好!!!

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

    推荐文章