I have a strange problem in iOS 9 with Swift 2.0 . I added a UISearchController to my tableViewController , but this causes a strange black screen problem. When I click on the search bar and write something, it shows the filtering results without any problems, but when I click on another button of the tab bar, for example Bookmarks , and after that when I click on tableViewController, which is Most popular again shows the black screen like a screen.
There is my tableViewController ;
import UIKit class CitiesTableViewController: UITableViewController, UISearchResultsUpdating { // MARK: - Class Properties private var cities = [String]() private var veterinaries = [Veterinary]() private var filteredVeterinaries = [Veterinary]() private var resultSearchController: UISearchController! // MARK: - TableViewController Life Cycle Methods override func viewDidLoad() { super.viewDidLoad() self.getCitiesList() self.configureResultsSearchController() } override func viewDidDisappear(animated: Bool) { super.viewDidDisappear(animated) self.resultSearchController.active = false } // MARK: - Configuring Search Bar Controller private func configureResultsSearchController() { self.resultSearchController = UISearchController(searchResultsController: nil) self.resultSearchController.searchResultsUpdater = self self.resultSearchController.dimsBackgroundDuringPresentation = false self.resultSearchController.hidesNavigationBarDuringPresentation = false self.resultSearchController.searchBar.sizeToFit() self.resultSearchController.searchBar.placeholder = "Klinik veya ilรงe adฤฑ" self.tableView.tableHeaderView = self.resultSearchController.searchBar } // MARK: - Table view data source override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if self.resultSearchController.active { return self.filteredVeterinaries.count } else { return self.cities.count } } // MARK: - Table view Delegate Methods override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if (self.resultSearchController.active) { self.performSegueWithIdentifier(Constants.ShowDetailViewControllerSegueIdentifier, sender: nil) } else { self.performSegueWithIdentifier(Constants.ShowTownsTableViewControllerSegueIdentifier, sender: nil) } } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier(Constants.CellIdentifier, forIndexPath: indexPath) if (self.resultSearchController.active) { cell.textLabel?.text = self.filteredVeterinaries[indexPath.row].name cell.detailTextLabel?.text = self.filteredVeterinaries[indexPath.row].address return cell } else { cell.textLabel?.text = self.cities[indexPath.row] return cell } } // MARK: - PARSE Query Methods private func getCitiesList() { let parseQueries = ParseQueries() parseQueries.downloadListData() { (let parseResults) in if let veterinaries = parseResults as? [Veterinary] { self.veterinaries = veterinaries for vet in veterinaries { if let city = vet.city { self.cities.append(city) } } dispatch_async(dispatch_get_main_queue()) { self.cities = HelperMethods().removeDuplicatesAndSort(array: self.cities) self.tableView.reloadData() } } } } // MARK: - UISearchController Delegate Methods func updateSearchResultsForSearchController(searchController: UISearchController) { self.filteredVeterinaries.removeAll(keepCapacity: false) if let searchBarText = searchController.searchBar.text{ let searchText = searchBarText.lowercaseString // Searching with Veterinary Name and Veterinary City self.filteredVeterinaries = self.veterinaries.filter({$0.name?.lowercaseString.rangeOfString(searchText) != nil}) self.filteredVeterinaries += self.veterinaries.filter({$0.town?.lowercaseString.rangeOfString(searchText) != nil}) tableView.reloadData() } }
This is a black screen image from the iOS 9 simulator, the same as the real device. 
I think it deinits my tableView when I click on searchBar and it cannot be initialized again. Is this a mistake or something else?
How can I solve this problem?
Thanks!
source share