views:

2002

answers:

3

I've got a UITableView with a UISearchBar as the tableViews.tableHeaderView. Just like the new Mail.app, Notes.app, etc. in 3.0. I want to hide the SearchBar until the user drags it in his sight.

My attempt only works when there're a couple of items in the tableView, so that the tableView actually wants to scroll. I call this in loadView:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self._tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

Nevertheless it seems that Apple handles such a serachbar differently. After draging out the searchbar it doesn't seem to be bounded to the tablecells anymore (in Notes.app, not in Mail.app).

But perhaps Apple has a distinct method for that new 3.0 behaviour, and I just can't find it?

+6  A: 

Maybe you can try it this way...

[self.tableView setContentOffset:CGPointMake(0,40)];
+4  A: 

Worked for me too. I used the following:

[self.tableView setContentOffset:CGPointMake(0,self.searchDisplayController.searchBar.frame.size.height)];

to query the height of the status bar.

petert