2009-05-08 12 views
6

Tengo un UITableView con una UISearchBar en la parte superior.iPhone UITableView con UISearchBar y el refrescante índice de sección

También uso el delegado de Section Index para mostrar ABC ... XYZ en el lado derecho.

problema se produce cuando hago clic en el cuadro de búsqueda y el teclado viene desde el fondo, las calabazas Sección Índice de modo que sólo una D ... * Z se visualizan - cuando cierro la búsqueda y el teclado desaparece , el índice permanece en este estado "aplastado" hasta que me desplazo o 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]; 

Mis preguntas son, ¿Alguien ha visto este comportamiento? ¿Hay alguna manera de volver a dibujar el índice de la sección en el RHS ([[self tableView] reloadData] no hace el truco)

¡Gracias un millón!

Respuesta

4

Debe desactivar el dibujo de índices cuando la búsqueda está activada por completo. Simplemente devuelva nil en su delegado, algo como esto:

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

    ... 
} 
2

Usted podría tratar de usar

- (void)flashScrollIndicators 

que refresca la barra de desplazamiento y es de esperar que el índice sección también?

+0

He editado mi post anterior para mostrar el código exacto que estoy usando ... en vano! – adam

1

¡¡Funciona bien !!!

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

+0

Éste realmente funcionó para mí, pero desafortunadamente es una API no documentada :( –

Cuestiones relacionadas