Sam
Sam

Reputation: 541

Implement UISearchController with table view initially hidden in Swift iOS 9

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

Upvotes: 1

Views: 411

Answers (1)

Pranav Wadhwa
Pranav Wadhwa

Reputation: 7746

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 :)

Upvotes: 1

Related Questions