UISearchController doesn't want to appear because he is not in view hierarchy

1.7k Views Asked by At

I am trying to make search in my UITableViewController using UISearchController. For starter project i use Apple's example. I made some changes and I want to use one class instead of thee as in example. I am adding my UISearchController from code. My problem is I cannot call UISearchController because of exeption :

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 project with changes

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

2

There are 2 best solutions below

0
On BEST ANSWER

Problem is that I wanted to run UISearchController :

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

Solution is to initialise UISearchController :

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

and leave storyboard as it was.

3
On

Updated answer:

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

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

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