UISearchController 不想出现,因为他不在视图层次结构中

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

我正在尝试使用 UISearchController 在我的 UITableViewController 中进行搜索。对于入门项目,我使用 Apple's example。 我做了一些更改,我想使用一个 class 而不是示例中的 thee。我正在从代码中添加我的 UISearchController。我的问题是由于异常我无法调用 UISearchController:

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

有人可以告诉我我做错了什么吗? 谢谢!

更新的答案:

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

对于那些想要带有搜索结果的工作示例的人,请参阅我的存储库 https://github.com/Optimbyte/IOSVC-master

旧答案: 我想你忘了在 MainStoryBoard 中添加一个搜索栏和搜索显示控制器。

问题是我想 运行 UISearchController :

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

解决方案是初始化 UISearchController :

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

并保留故事板原样。