I added a search bar into my TableViewController's header, and I've also added a "{search}" to the "sectionIndexTitlesForTableView" array. Now on the right side, I got the letters of the alphabet + the search symbol on the top... to scroll to the sections of the letters (not the search field) I used this:
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
return index -1;
}
now when I click the letter A, it scrolls to the section A and so on. Only I can't make the "search symbol" scroll to the search bar in the tableView's header...
How can I do this?
Thank you in advance...
If the Search bar is at the very top of the tableView, you could do something like-
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
// as the search icon is at index 0, scroll to the top
if(index == 0)
[tableView scrollRectToVisible:CGRectMake(0, 0, searchBar.width, searchBar.height) animated:YES];
return index -1;
}
Else, if it is a section without any rows, you could do-
CGRect searchBarRect = [tableView rectForSection:searchBarIndex];
[tableView scrollRectToVisible:searchBarRect animated:YES];
HTH,
Akshay
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