0

I used very similar code for another app and the search bar behaves as it should. For some reason, this code below does not work with my current app. Searching online did not yield any answers. The delegate functions aren't the cause of it as when I comment out all their code, it results in the exact same behavior. In fact, when I comment out most of this code below, it results in the same behavior. I don't know why tapping on search destroys my ui. Am I missing something? I must be...

private func configureSearchBar() {
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.showsCancelButton = true
    searchController.searchBar.delegate = self
    searchController.searchBar.isUserInteractionEnabled = true
    definesPresentationContext = true
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(searchController.searchBar)
    searchController.searchBar.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true
    searchController.searchBar.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20).isActive = true
    searchController.searchBar.heightAnchor.constraint(equalToConstant: 55).isActive = true
    searchController.searchBar.topAnchor.constraint(equalTo: agendaLabel.bottomAnchor, constant: 8).isActive = true
    let color:UIColor = .journeyGold
    let lightGold = color.withAlphaComponent(0.5)
    searchController.searchBar.tintColor = lightGold
    searchController.searchBar.barTintColor = lightGold
    searchController.searchBar.backgroundColor = lightGold
    searchController.searchBar.layer.borderColor = lightGold.cgColor
    navigationItem.hidesSearchBarWhenScrolling = false
    searchController.hidesNavigationBarDuringPresentation = true
    searchController.searchBar.text = ""
    searchController.searchBar.setShowsCancelButton(true, animated: false)
}
michaeldebo
  • 3,065
  • 4
  • 14
  • 20
  • What exactly is your question? – koen Apr 13 '20 at 19:19
  • How do I fix the problem of my tableview and search bar disappearing upon the search bar being tapped? I'd like to not have my tableview disappear nor the search bar. – michaeldebo Apr 13 '20 at 19:23
  • What do you mean by disappear - could you add a screenshot? – koen Apr 13 '20 at 19:32
  • It’s just a blank screen that’s the view controller’s view’s background color except for a label that says agenda that was above the search bar and tableview when it was there. Not sure what a screenshot would further reveal. – michaeldebo Apr 14 '20 at 01:37
  • Then please share some relevant code as a [example]. You already stated that the code above is not related. Now it’s just a guessing game. See also [ask]. – koen Apr 14 '20 at 02:16
  • The problem is I don't see what code is more relevant than what I showed. The view controller is huge with 1600+ lines. I shared the code that relates to the search controller. – michaeldebo Apr 14 '20 at 14:13
  • Does this answer your question? [Search Bar disappears after tap on it](https://stackoverflow.com/questions/29683193/search-bar-disappears-after-tap-on-it) – koen Apr 14 '20 at 19:52

0 Answers0