【问题标题】:How to preload UISearchDisplayController with a search string如何使用搜索字符串预加载 UISearchDisplayController
【发布时间】:2013-01-22 15:10:45
【问题描述】:

我正在尝试使用 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。

【问题讨论】:

  • 答案解决了你的问题吗?
  • 没有。我最终没有使用 searchDisplayController。不确定,但我想我也尝试过你的组合,但没有成功
  • 好的,谢谢分享。

标签: ios uisearchbar uisearchdisplaycontroller


【解决方案1】:

您是否尝试过这样的事情(仅基于引发的异常):

[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];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多