2013-09-30 18 views
5

Prima di iOS7, abbiamo aggiunto un'icona a forma di lente di ingrandimento nella parte superiore dell'indice UITableView anteponendo UITableViewIndexSearch ai titoli dell'indice di sezione.Indice della sezione UITableView non in grado di scorrere fino all'indice della barra di ricerca

trascinandolo sull'icona lente di ingrandimento nell'indice sezione, tableView può scorrere a searchbar con il codice seguente:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 

    NSInteger resultIndex = [self getSectionForSectionIndex:index]; 

    // if magnifying glass 
    if (resultIndex == NSNotFound) { 
     [tableView setContentOffset:CGPointZero animated:NO]; 
     return NSNotFound; 
    } 
    else { 
     return resultIndex; 
    } 
} 

Tuttavia in iOS 7, ciò scorrere solo alla prima sezione anziché la barra di ricerca.

risposta

9

Per risolvere questo abbiamo adattato il contenuto di offset per tenere conto di incasso contenuto del UITableView introdotto in iOS 7: CGPointMake(0.0, -tableView.contentInset.top)

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 

    NSInteger resultIndex = [self getSectionForSectionIndex:index]; 

    // if magnifying glass 
    if (resultIndex == NSNotFound) { 
     [tableView setContentOffset:CGPointMake(0.0, -tableView.contentInset.top)]; 
     return NSNotFound; 
    } 
    else { 
     return resultIndex; 
    } 
} 
Problemi correlati