![](/img/trans.png)
[英]UISearchDisplayController - how to preload searchResultTableView
[英]How to preload UISearchDisplayController with a search string
我正在尝试使用searchString预加载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被隐藏。 但是,如果我按下searchBar上的“取消”按钮,它将崩溃:
*-[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。
您是否尝试过这样的事情(仅基于引发的异常):
[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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.