Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll UITableView so that the header isn't visible

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?

like image 314
Jens Kohl Avatar asked Sep 11 '25 10:09

Jens Kohl


2 Answers

Maybe you can try it this way...

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

Worked for me too. I used the following:

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

to query the height of the search bar.

like image 36
petert Avatar answered Sep 12 '25 23:09

petert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!