-2

When I search for tutorials about the UISearchBar online, they usually talk about creating a search bar in the same UITableVie as the one displaying unfiltered data.

I would like to create a UISearchBar and a search button, then use a second, seperate, tableview to display the search results, just like some of Google's iOS apps.

How might I achieve this?

Moshe
  • 57,511
  • 78
  • 272
  • 425
  • iPhone Google App starts with one view controller and there is an image of a searchBar which actually doesn't do anything. When you click on it, another viewcontroller opens with its own search bar where you enter your search phrase. It does NOT link to another tableview as you say. – oyalhi Apr 26 '16 at 11:41
  • but after i enter something in search bar then click search button, it will appear a table of search result, that's what i want to do. – Herman Kwok Apr 26 '16 at 11:55
  • While typing the search bar it opens up a view and shows results where you can click in a tableview. Is this what you mean? – oyalhi Apr 26 '16 at 11:56

1 Answers1

0

Below is just an example to get you started.

First define the location of the view controller:

    let contentRect = CGRectMake(0, 30, self.view.bounds.size.width, 100)

Then you need to setup your UITableViewController and set the delegate and the datasource and add it as a child view to the main view controller:

    resultsController = UITableViewController(style: UITableViewStyle.Plain)
    resultsController.tableView.delegate = self
    resultsController.tableView.dataSource = self
    resultsController.view.frame = contentRect
    self.addChildViewController(resultsController)
    self.view.addSubview(resultsController.view)
    resultsController.didMoveToParentViewController(self)

You put the entire code where you want to show the search results tableview.

oyalhi
  • 3,834
  • 4
  • 40
  • 45