うちのいぬ Tech Blog

Tech Blog of Uchinoinu/My dog

Back Button of NavBar Tapped when Incrementally Searching using SearchBarNavigationBar, search function cannot act correctly

Environment

Situation

  • Implement Incremental Search in TableViewController using SearchBar
  • Input search word
  • Leave by back button of nav bar, not x button or cancel button
  • Search cannot move correctly.

Initial View of Search

f:id:susanne:20160907143444p:plain

FirstResponder moves to search bar, and ....

f:id:susanne:20160907143456p:plain

date become vacant

incremental search

f:id:susanne:20160907143449p:plain

By inputting a character, result change.

But

Leave by back button of navigation item, not x button or cancel button, try to search again, and never go well. f:id:susanne:20160907143453p:plain

Cannot search correctly. Data does not change cancel button never been shown

solution

-set active of UISearchController false in viewWillDisappear

    var resultSearchController = UISearchController()

    override func viewWillDisappear(animated: Bool) {
        self.resultSearchController.active = false
    }

Solved well.