1

ОЖИДАЕТСЯ:экран лаги, когда UISearchController отклонил

Когда UIButton сливают, показывают ViewController модально, который имеет поисковую контроллер и TableView с результатами.

При нажатии на элемент в списке измените текст строки поиска на то, что было нажато, и отпустите диспетчер представлений обратно к оригиналу, когда UIButton теперь настроен на этот текст.

Actual:

UIButton вызывает переход к searchViewController. searchViewController показывает и правильно настраивает searchController и tableView. Нажатие на ячейку вызывает выход, выходящий на исходный экран, и корректно обновляет текст в UIButton и searchbar ...

но, безнадежный белый экран отстает на развязке и сводит меня с ума.

Смягчение пытался:

  1. Переоформление в searchController затем вызывая SEGUE программно
  2. Calling self.dismiss (анимированный: истинное завершение: ноль) в didSelectRowAt
  3. Если собрать смещать на главной thread with: DispatchQueue.main.async {}
  4. вызов self.presentingViewController? .dismiss (анимированный: true)

ВидеоDemo of flashing

Код:

SearchDetailsViewController - ViewController для отдыха в

import UIKit 

class SearchDetailsViewController: UIViewController { 

    @IBOutlet weak var destinationButton: UIButton! 
    override func viewDidLoad() { 
    super.viewDidLoad() 
    } 

    override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 

    if searchDestination != "" { 
     destinationButton.setTitle(searchDestination, for: UIControlState.normal) 
     destinationButton.setTitleColor(UIColor.black, for: UIControlState.normal) 
    } else { 
     destinationButton.setTitle("Search Nearby", for: UIControlState.normal) 
    } 
    } 

    @IBAction func unwindToSearchDetailsViewController(segue: UIStoryboardSegue){ 
    } 
} 

SearchViewController - проблема ребенка. В настоящее время у меня есть ячейка tableview в качестве выходного segue в раскадровке.

class SearchViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchResultsUpdating, UISearchBarDelegate, UISearchControllerDelegate { 


    @IBOutlet weak var searchResultsTableView: UITableView! 

    var destinationsObj:[String:[String]] = [:] 
    var destinations:[String] = [] 
    var defaultDestinations:[String] = ["Search Nearby"] 
    var filteredDestinations:[String] = ["Search Nearby"] 
    var shouldShowSearchResults = false 

    var searchActive:Bool = false 
    var searchController: UISearchController! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     defaultDestinations = recentSearches 
     configureTableView() 
     configureSearchController() 

    } 

    override func viewDidAppear(_ animated: Bool) { 
     // Show search bar keyboard 
     searchController.isActive = true 
     DispatchQueue.main.async { 
      self.searchController.searchBar.becomeFirstResponder() 
     } 

    } 


    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    // MARK: Configure Functions 
    func configureSearchController() { 
     searchController = UISearchController(searchResultsController: nil) //nil lets the view controller also be the search results 
     searchController.searchResultsUpdater = self 
     searchController.dimsBackgroundDuringPresentation = false 

     searchController.searchBar.placeholder = "Where to?" 
     searchController.searchBar.delegate = self 

     searchController.searchBar.sizeToFit() 
     searchResultsTableView.tableHeaderView = searchController.searchBar 
     searchController.delegate = self 

    } 

    func configureTableView() { 
     searchResultsTableView.delegate = self 
     searchResultsTableView.dataSource = self 

     //searchResultsTableView.isMultipleTouchEnabled = false 
    } 

    // MARK: TableView Delegate Functions 
    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

     if shouldShowSearchResults { 
      return filteredDestinations.count 
     } else { 
      return defaultDestinations.count 
     } 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "idCell", for: indexPath) 

     if shouldShowSearchResults { 
      cell.textLabel?.text = filteredDestinations[indexPath.row] 
     } else { 

      cell.textLabel?.text = defaultDestinations[indexPath.row] 
     } 

     return cell 
    } 

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     return 40.0 
    } 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 


     if let value = tableView.cellForRow(at: indexPath)?.textLabel?.text { 
      self.searchController.searchBar.text = value 
      searchDestination = value 
      if !recentSearches.contains(value) { 
       recentSearches.append(value) 
      } 

     } 
     //self.searchController.resignFirstResponder() 
//  tableView.deselectRow(at: indexPath, animated: false) 
//  DispatchQueue.main.async { 
//   self.dismiss(animated: true, completion: nil) 
//  } 

     // self.performSegue(withIdentifier: "cancelSearchSegue", sender: self) 
    } 

    // MARK: UISearchBar Delegate Functions 
    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) { 
     searchBar.resignFirstResponder() 
     //self.dismiss(animated: true, completion: nil) 
     self.performSegue(withIdentifier: "cancelSearchSegue", sender: self) 
    } 

    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { 

     if let value = searchBar.text { 
      searchDestination = value 
      if !recentSearches.contains(value) { 
       recentSearches.append(value) 
      } 
     } 


     //self.dismiss(animated: true, completion: nil) 
     self.performSegue(withIdentifier: "cancelSearchSegue", sender: self) 
    } 

    func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { 

    } 


    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { 
     shouldShowSearchResults = true 
     if searchText.characters.count > 1 { 
      return 
     } else { 
      if let firstLetter = searchText.characters.first{ 
       print("Typed \(firstLetter)") 
       getPredictionData(firstLetter:firstLetter.description) 
      } 
     } 
    } 

    func dismissCurrentView() { 
     // self.presentingViewController?.dismiss(animated: true, completion: nil) 
     self.performSegue(withIdentifier: "cancelSearchSegue", sender: self) 
    } 

Screenshot of my storyboard

ответ

0

Ну, я думал, что я отправляю ответ упаковывают это случается с кем-либо еще.

В ViewDidAppear, я установка searchController к активному searchController.isActive = истинный

Ну, прежде чем я уволен, мне нужно, чтобы установить его в неактивное состояние!

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    if let value = tableView.cellForRow(at: indexPath)?.textLabel?.text { 
    self.searchController.searchBar.text = value 
    searchDestination = value 
    if !recentSearches.contains(value) { 
     recentSearches.append(value) 
    } 
    } 
self.searchController.isActive = false 
self.performSegue(withIdentifier: "cancelSearchSegue", sender: self) 
} 
0

Не выполняйте SEGUE, попытайтесь отклонить вид контроллера непосредственно и перед Dismissing установить свойство представления вида контроллера к результату поиска

+0

я нашел ответ после размещения его не очень долго. Мне нужно было отключить контроллер поиска до активного, прежде чем отклонить его. –

Смежные вопросы