views:

3141

answers:

4

I have a UITableView with a UISearchBar at the top of it.

I also use the Section Index delegate to display ABC...XYZ on the right hand side.

Problem occurs when I click on the Search Box and the keyboard comes up from the bottom, the Section Index squashes so only A*D*...*Z are displayed - when I close the Search and they keyboard goes away, the Index stays in this "squashed" state until I scroll or similar.

    // 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];

My questions are, has anyone seen this behaviour? Is there a way to redraw the Section Index on the RHS ([[self tableView] reloadData] doesn't do the trick)

Thanks a million!

+2  A: 

You could try using

- (void)flashScrollIndicators

which refreshes the scrollbar and hopefully the section index too?

h4xxr
i've edited my above post to show the exact code i am using... to no avail!
adam
A: 

i have the same problem like adam and i am trying to lose hope.

- (void)flashScrollIndicators

i tried as well but it did not fix my problem.

in case anyone found a solution to the problem... please let us know here.

+2  A: 

You should disable the drawing of indexes in when search is activated altogether. Simply return nil in your delegate, something like this:

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

  ...
}
Boon
A: 

It work fine!!!

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

Oscar