当放置在UITableViewController的顶部时看不到搜索栏

问题描述:

我已经在我的UITableViewController的顶部放置了一个searchBar,我不知道如何使它可见。我不想使用searchController.searchBar(它将搜索栏放置在tableView的标题中),因为我对使用UISearchBarDelegate感兴趣。我通过故事板完成了上述内容。如何在UITableView控制器的标题中放置一个搜索栏?当放置在UITableViewController的顶部时看不到搜索栏

只需拖动ñ在表视图控制器的顶部下降搜索栏(只以上prototypecell) enter image description here

enter image description here

+0

感谢花花公子程序添加搜索栏。不知道我是如何错过的。一直在尝试! – tim

在迅速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;