1

I am trying to implement search bar in a view which would display filtered info as typed in the search bar dynamically in a table view. Also table view should initially be hidden until user doesn't starts typing. I have searched for the same but all I got was search controller embeded in table view header where table view is already there with some other info to display. Following image is what I have tried so farenter image description here

Underlying is a mapview therefor I am unable to set table view initially shown

Sam
  • 521
  • 1
  • 6
  • 23

1 Answers1

1

Show the table in the searchBarShouldBeginEditing method.

func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
    //Currently Table is hidden
    table.alpha = 0
    table.isHidden = false
    UIView.animate(withDuration: 0.5) { 
        self.table.alpha = 1
    }
    return true
}

Note: this is in Swift 3 :)

Pranav Wadhwa
  • 7,666
  • 6
  • 39
  • 61
  • but search bar is added in table view header. – Sam Jun 21 '16 at 13:56
  • I do not believe you can hide the tableview, but show the search bar. I suggest taking it out. It may be a hassle at first, but it will be helpful later on. – Pranav Wadhwa Jun 21 '16 at 15:43