我在我的UITableViewController顶部放置了一个searchBar,我不知道如何让它可见。我不想使用searchController.searchBar(它将搜索栏放在tableView的标题中)因为我对使用UISearchBarDelegate感兴趣。我通过故事板完成了上述工作。如何将搜索栏放在UITableView控制器的标题中?
答案 0 :(得分:2)
答案 1 :(得分:0)
以编程方式在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;
答案 2 :(得分:0)