views:

57

answers:

1

I have a tableview with an indexed scrollbar on the right side that shows the letters A-Z and has a magnifying glass icon at the top ({search}). All of the letters in the scrollbar appropriately take the user to the corresponding section except for the magnifying glass, which takes the user to "A" and keeps the searchBar hidden.

I just want it to go to the very top of the table so that the searchBar shows up when the user taps the magnifying glass icon in the scroll bar. I've been looking all over for ways to do this, but I can't find any way shy of adding the searchBar to the first tableCell and it's own section, which I'd prefer not to do unless it's the only way.

Thanks so much!

A: 

Try this post - I wanted the same sort of thing a while ago, hope it helps.

In short, I put the search bar in the header view of the table view, then adjust it's contentOffset to show it when the {search} is touched.

Actually I was able to mimic the behaviour of Apple apps too, so when the view appears each time the search bar is re-hidden, if required - I used UISearchDisplayController to handle the UISearcBar for me. Here's the bit of code I put in my UITableViewController class to do this:

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];

  if (self.tableView.contentOffset.y <
      self.searchDisplayController.searchBar.frame.size.height)
    {
      self.tableView.contentOffset =
        CGPointMake(0, self.searchDisplayController.searchBar.frame.size.height);
    }
}
petert
Thanks for the link to your previous post. I'm wondering what "Make the sectionIndexSection for the search -1" means in your answer?
Gorgando
I'm not near my code now, but if your section index is {search} plus A to Z you can make an NSArray of indexes to return, so A is 0, B is 1 etc. Just make the first item in this array -1 (if search at top), then check the UiTableView delegate methods for section indexes.
petert