Reputation: 173
I have placed a searchBar at the top of my UITableViewController and I do not know how to make it visible. I do not want to use searchController.searchBar (which does place the searchbar in the header of the tableView) because I am interested in using the UISearchBarDelegate. I accomplished the above via the storyboard. How do I place a searchbar in the header of the UITableView Controller?
Upvotes: 1
Views: 368
Reputation: 875
Sometimes SearchBar's height is 0.
I don't know why, but anyway try set constraints height = 44
and in the inspector window, you can set the red corlor for finding it easy.
Upvotes: 0
Reputation: 636
Add search bar programmatically in swift 3+
private var searchBar: UISearchBar!
let searchBarView = UIView(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(UIScreen.main.bounds.size.width), height: CGFloat(45)))
searchBar = UISearchBar()
searchBar.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width , height: 44)
searchBar.searchBarStyle = UISearchBarStyle.prominent
searchBar.placeholder = " Search..."
searchBar.sizeToFit()
searchBar.isTranslucent = false
searchBar.delegate = self
searchBarView .addSubview(searchBar)
tableView.tableHeaderView=searchBarView;
Upvotes: 0
Reputation: 508
Just drag n drop search bar at top of table view controller (just above to prototypecell)
Upvotes: 3