Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 625
Yurii Boiko Avatar asked Jun 18 '15 10:06

Yurii Boiko


2 Answers

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

like image 56
ares777 Avatar answered Sep 23 '22 23:09

ares777


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.

like image 45
Yurii Boiko Avatar answered Sep 20 '22 23:09

Yurii Boiko