0
votes

I have a UITableView which has UISearchController (added programmatically). SearchController is added to header of TableView.(screenshot 2). However, I want to have a search view first in the middle of screen when app opens and after user starts to search, TableView appears and start to show datas.(screenshot 1)

I try to add UISearchBar inside Storyboard and connect it to UISearchController but can't assign it directly.

Screenshot 2 Screenshot 1

let searchController = UISearchController(searchResultsController: nil)

override func viewDidLoad() {
    super.viewDidLoad()
    // Setup the Search Controller
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    definesPresentationContext = true
    mTableView.tableHeaderView = searchController.searchBar }
2

2 Answers

0
votes

1# You can work around this point by change tableview size and position at start by tableview to middle of screen as you want , after user start search you can change frame to View Boundary

2# Better => you can use UItextField to create your own search Controler and custamize as wanted

0
votes

I solve it by creating a UIView inside storyboard and add searchcontroller inside the view.

  1. Create a UIView in Storyboard
  2. Add IBOutlet
  3. Add SearchController as a subview of UIView.