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 AD...*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!
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; ... }
You could try using
- (void)flashScrollIndicators
which refreshes the scrollbar and hopefully the section index too?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With