Ios 如何使用搜索字符串预加载UISearchDisplayController

Ios 如何使用搜索字符串预加载UISearchDisplayController,ios,uisearchbar,uisearchdisplaycontroller,Ios,Uisearchbar,Uisearchdisplaycontroller,我正在尝试使用搜索字符串预加载UISearchBar 在当前设置中。我正在UITableViewController中使用UISearchDisplayController 我使用的第一种方法是通过以下方法设置搜索字符串: - (void) presetSearchDisplayControllerWithString:(NSString*)searchString{ [self.searchDisplayController setActive:YES animated:NO];

我正在尝试使用搜索字符串预加载UISearchBar

在当前设置中。我正在UITableViewController中使用UISearchDisplayController

我使用的第一种方法是通过以下方法设置搜索字符串:

- (void) presetSearchDisplayControllerWithString:(NSString*)searchString{
    [self.searchDisplayController setActive:YES animated:NO];
    [self.tableView setContentOffset:CGPointMake(0, 0)];
    self.searchBar.text = searchString;
    self.searchFetchedResultsController = [self   createFetchedResultsControllerWithSearchTerm:searchString];
}
它起作用了。UISearchbar显示搜索字符串,隐藏原始tableView和TableViewIndex。但如果我按下搜索栏上的“取消”按钮,它会崩溃:

*在-[UISearchDisplayController setActive:animated:]、/SourceCache/UIKit_Sim/UIKit-2372/UISearchDisplayController.m:682中断言失败 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因是:“搜索内容导航控制器不能在-setActive:YES和-setActive:NO之间更改”*

第二个瓦里安也不工作

- (void) searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
    [self.searchDisplayController.searchBar setText:@"rune"];
}

嗯,如果你点击搜索栏,它就会工作。但在您完成之前,它只显示常规的tableView。

您是否尝试过类似的操作(仅基于引发的异常):


答案解决了你的问题吗?没有。我最终没有使用searchDisplayController。不确定,但我想我也试过你的组合,但没有成功,谢谢分享。
[self.searchDisplayController setActive:NO animated:NO];
self.searchBar.text = searchString;
[self.searchDisplayController setActive:YES animated:NO];
[self.tableView setContentOffset:CGPointMake(0, 0)];
self.searchFetchedResultsController = [self createFetchedResultsControllerWithSearchTerm:searchString];