3

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.

Guy Daher
  • 5,526
  • 5
  • 42
  • 67

2 Answers2

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
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