开发者

UISearchBar on the top of UITableView which can hide but stay close to UINavigationBar

I would like to have a UISearchBar on the top of my UITableView which hides when you scroll down: The answer is easy, I just need to add it on my table view header like this:

UISearchBar *search = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
s开发者_如何学运维elf.tableView.tableHeaderView = search;
[search release];

But the problem is that when you scroll up the UISearchBar fit to the top of the UITableView, and not the top of the UINavigationBar. To be more clear I made a screen in Mail (not good) and Game Center (good).

UISearchBar on the top of UITableView which can hide but stay close to UINavigationBar

I want the same as in Game Center. Do you have any idea how they are doing this ?


You will need to hide the search bar on your own when you scroll the tableview. So, don't put it as a UITableView header. You could hide it by setting its height to zero. That way if your tableview is set to autoresize it will expand.

I would experiment with having the UITableView and the UISearchBar as peers within another view. The GameCenter image does not have the search bar as the table view header, rather it has them as separate subviews.

You could also look at UISearchDisplayController but I think it doesn't quite have the behaviour that you want.

Edit: This question is basically your question and has some code in the answers.


A tableview header will move while scrolling downwards. It is tableview's property. If you want to place a searchBar with navigation bar. Why dont you place the search bar just below the navigation bar. Use search bar and separate tableview.


The right side 's UISearchBar is on the another UIView, it is not a part of UITableView. So, you can add a child view to put the UISearchBar, and another child view is for the UITableView.


This will answer your question :

iPhone: Hide UITableView search bar by default

same concept, different controller.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜