I have a UItableView with a UISearchBar on top of it I was wondering if there was a way to keep the UIsearchBar visible even when the user is sliding down to check the lower parts of the tableView.
Asked
Active
Viewed 2,331 times
2 Answers
3
You have to add the UISearchBar to the View not to the UITableView.Then when you are scrolling the tableview the search bar is not subview of tableview.So it don't scroll.It keeps remain

Tendulkar
- 5,550
- 2
- 27
- 53
-
I thought of that but my xib file only contains a tableView, and when I put the UIsearchbar outside of the tableView, It won't appear anymore... Any ideas how to fix? – Guy Daher Feb 18 '12 at 10:34
-
can you tell me the superclass of your class in which your tableview presented? – Tendulkar Feb 18 '12 at 10:36
-
The xib file of the superclass is a normal UIView – Guy Daher Feb 18 '12 at 10:59
-
then set the frames like search bar.frame = CGRectMake(0.0.320,30);tableview.frame = CGRectMake(0,40,320,430); – Tendulkar Feb 18 '12 at 11:05
2
Here are the steps:
- Add UITableView in your xib
- Set Y origin for UITableView frame as 44
- Reduce height of UITableView frame with 44, now there would be some blank space at the top of UITableView
- Add UISearchBar in that blank space.
Done. Hope this is what you asked.
Enjoy Coding :)

Mrunal
- 13,982
- 6
- 52
- 96
-
the problem is that when using UITableViewController and dragging and dropping a UISearch bar onto it makes the UISearch bar scroll with the table. How should that be avoided in that case? – Sam B Jan 28 '16 at 12:53
-
either use a UIViewController with a UITableView in it, or add the UISearchBar as a subview of self.view in code, and then adjust the tableView's content insets. – Kamchatka Oct 28 '16 at 07:54