UISearchController does not want to appear because it is not in the hierarchy of views

I am trying to search my UITableViewController using a UISearchController. For a start-up project, I use the Apple example . I made some changes, and I want to use one class instead of you, as in the example. I am adding my UISearchController from code. My problem: I cannot call UISearchController due to an exception:

2015-06-18 13:35:04.750 TableSearch[4796:77813] Warning: Attempt to present <UISearchController: 0x7fe09b719f00> on <APLMainTableViewController: 0x7fe09b50e450> whose view is not in the window hierarchy! 

Working draft with changes

Can someone please tell me what I did wrong? Thanks!

+6
source share
2 answers

The problem is that I wanted to run the UISearchController:

 self.searchController = [[UISearchController alloc] initWithSearchResultsController:self]; 

The solution is to initialize the UISearchController:

 self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; 

and leave the storyboard as it is.

+1
source

Updated answer:

  self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; 

For those looking for a working example with search results, see my repo https://github.com/Optimbyte/IOSVC-master

Old answer: I think you forgot to add a search bar and a search display controller to the MainStoryBoard. required

+7
source

Source: https://habr.com/ru/post/989341/


All Articles