Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing ViewController with SearchController showing black rectangle under Search Bar

When I push another controller on to the stack (When having a Search Controller) I get a black block under the search bar. I have set the background colour to white on all the below;

  • Search Controller
  • Search Bar
  • Current VC
  • Next VC

It also appears when going back in the stack.

Search Controller

func setUpSearchController() {
        searchController.delegate = self
        searchController.view.backgroundColor = .white
        searchController.searchBar.backgroundColor = .white
        searchController = UISearchController(searchResultsController: nil)
        searchController.hidesNavigationBarDuringPresentation = true
        searchController.dimsBackgroundDuringPresentation = true
        searchController.searchBar.sizeToFit()
        searchController.searchBar.backgroundColor = .white
        searchController.searchBar.barTintColor = .white
        searchController.searchBar.placeholder = "Search"
        searchController.searchBar.searchBarStyle = .minimal
        searchController.searchBar.tintColor = Colours.brandGreen
        definesPresentationContext = true
        if #available(iOS 11.0, *) {
            navigationItem.searchController = searchController
            navigationItem.hidesSearchBarWhenScrolling = true
        } else {
            messagesTableView.tableHeaderView = searchController.searchBar
        }
    }

Did Select Cell

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let chatController = ChatController()
        let message = messages[indexPath.row]
        chatController.title = message
        self.navigationController?.pushViewController(chatController, animated: true)
    }

illustration

As always any help greatly appreciated.

like image 801
David Lintin Avatar asked Jul 13 '18 10:07

David Lintin


1 Answers

Found the answer here: https://blog.kulman.sk/fixing-black-artifact-changing-large-tiles-mode/

Code

guard let navigationController = navigationController else { return }
navigationController.view.backgroundColor = .white

As the above link explains this cannot be set globally, therefore, would need to be on each NC I will be using.

like image 74
David Lintin Avatar answered Nov 15 '22 16:11

David Lintin